• poj 1703


    #include<stdio.h>
    #include<string.h>
    #define N 100010
    int father[N],link[N];
    int find(int x) {
     if(x!=father[x]) {
      int h=father[x];
      father[x]=find(father[x]);
      link[x]=(link[x]+link[h])%2;
     }
     return father[x];
    }
    void insert(int x,int y) {
     int xx=find(x);
     int yy=find(y);
     father[xx]=yy;
     link[xx]=(link[x]+link[y]+1)%2;
    }
    int main() {
     int t,n,m,a,b,i,f1,f2;
     char s[3];
     scanf("%d",&t);
     while(t--) {
      scanf("%d%d",&n,&m);
      for(i=1;i<=n;i++)
       father[i]=i;
      memset(link,0,sizeof(link));
      while(m--) { 
       scanf("%s%d%d",s,&a,&b);
       f1=find(a);
       f2=find(b); 
       if(f1==f2) {
        if(s[0]=='A') {
         if(link[a]==link[b])
          printf("In the same gang. ");
         else
           printf("In different gangs. ");
        }

       }
       else {
        if(s[0]=='A')
        printf("Not sure yet. ");
        else
        insert(a,b);
       }
      }
     }
     return 0;
    }

  • 相关阅读:
    linux日志守护进程 syslog
    ORM(一)
    ajax
    python bbs项目代码分析
    jquery基础
    PHP根据概率产生随机数
    用PHP删除文件操作unlink
    实时显示剩余可以输入的文字数
    mysql分表方法实现
    php 输出昨天,今天,明天是星期几的方法
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410894.html
Copyright © 2020-2023  润新知