标签:
链接:
http://poj.org/problem?id=1703
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 36768 | Accepted: 11294 |
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.
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <stdlib.h> #include <math.h> #include <queue> #include <algorithm> using namespace std; #define N 100005 #define INF 0x3f3f3f3f int f[N], r[N], vis[N]; int Find(int x) { int k = f[x]; if(x!=f[x]) { f[x] = Find(f[x]); r[x] = (r[x]+r[k])%2; } return f[x]; } int main() { int t; scanf("%d", &t); while(t--) { int n, m, i, a, b; char s[10]; scanf("%d%d", &n, &m); memset(r, 0, sizeof(r)); memset(vis, 0, sizeof(vis)); for(i=0; i<=n; i++) f[i] = i; for(i=1; i<=m; i++) { scanf("%s%d%d", s, &a, &b); if(s[0]==‘D‘) { int fa = Find(a); int fb = Find(b); if(fa!=fb) { f[fa]=fb; r[fa] = (r[a]-r[b]+3) % 2; } vis[a] = vis[b] = 1; } else { if(vis[a]==0 || vis[b]==0) printf("Not sure yet.\n"); else { int fa = Find(a); int fb = Find(b); if(fa!=fb) printf("Not sure yet.\n"); else { if(r[a]==r[b]) printf("In the same gang.\n"); else printf("In different gangs.\n"); } } } } } return 0; }
(带关系)Find them, Catch them -- poj -- 1703
标签:
原文地址:http://www.cnblogs.com/YY56/p/4789802.html