码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1703 Find them, Catch them

时间:2014-09-06 23:47:24      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   for   art   

这道题与POJ 2492 几乎一模一样,就不多说了,直接上代码吧

 

bubuko.com,布布扣
 1 //#define LOCAL
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6 
 7 const int maxn = 100000 + 10;
 8 int p[maxn], r[maxn];
 9 
10 int Find(int a)
11 {
12     if(p[a] == a)    return a;
13     int temp = p[a];
14     p[a] = Find(p[a]);
15     r[a] = (r[a] ^ r[temp]);
16     return p[a];
17 }
18 
19 int main(void)
20 {
21     #ifdef LOCAL
22         freopen("1703in.txt", "r", stdin);
23     #endif
24 
25     int T;
26     scanf("%d", &T);
27     while(T--)
28     {
29         int n, m, x, y;
30         char cmd[10];
31         scanf("%d %d", &n, &m);
32         for(int i = 0; i <= n; ++i)    p[i] = i;
33         memset(r, 0, sizeof(r));
34         for(int i = 0; i < m; ++i)
35         {
36             scanf("%s %d %d", cmd, &x, &y);
37             int px = Find(x);
38             int py = Find(y);
39             if(cmd[0] == A)
40             {
41                 if(px != py)
42                     printf("Not sure yet.\n");
43                 else
44                 {
45                     if((r[x] + r[y]) % 2)
46                         printf("In different gangs.\n");
47                     else
48                         printf("In the same gang.\n");
49                 }
50             }
51             else
52             {
53                 p[px] = py;
54                 r[px] = 1 - (r[x] ^ r[y]);
55             }
56         }
57     }
58     return 0;
59 }
代码君

 

POJ 1703 Find them, Catch them

标签:style   blog   http   color   os   io   ar   for   art   

原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/3959946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!