标签:secret from aos sam 关系 include key idt print
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 47222 | Accepted: 14543 |
Description
Input
Output
Sample Input
1 5 5 A 1 2 D 1 2 A 1 2 D 2 4 A 1 4
Sample Output
Not sure yet. In different gangs. In the same gang.
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 6 inline void read(int &x) 7 { 8 x = 0;char ch = getchar(),c = ch; 9 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 10 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 11 if(c == ‘-‘)x = -x; 12 } 13 14 const int MAXN = 100000 + 10; 15 16 int fa[MAXN], w[MAXN], t, n, m; 17 char s[1]; 18 19 int find(int x) 20 { 21 if(fa[x] == x)return x; 22 int f = find(fa[x]); 23 w[x] = w[fa[x]] ^ w[x]; 24 fa[x] = f; 25 return f; 26 } 27 28 int main() 29 { 30 read(t); 31 register int tmp,tmp1, tmp2, f1, f2; 32 for(;t;-- t) 33 { 34 read(n);read(m); 35 for(register int i = 1;i <= n;++ i)fa[i] = i, w[i] = 0; 36 for(register int i = 1;i <= m;++ i) 37 { 38 scanf("%s", s); 39 if(s[0] == ‘D‘) 40 { 41 read(tmp1), read(tmp2); 42 f1 = find(tmp1), f2 = find(tmp2); 43 tmp = w[tmp1] ^ w[tmp2] ^ 1; 44 fa[f1] = f2, w[f1] = tmp; 45 } 46 else 47 { 48 read(tmp1), read(tmp2); 49 f1 = find(tmp1), f2 = find(tmp2); 50 if(f1 == f2) 51 if(w[tmp1] == w[tmp2])printf("In the same gang.\n"); 52 else printf("In different gangs.\n"); 53 else printf("Not sure yet.\n"); 54 } 55 } 56 } 57 return 0; 58 }
标签:secret from aos sam 关系 include key idt print
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7476699.html