Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
俺第一次贴代码,实在是找不出 wa 在哪里了,拜谢各位同学帮忙看一下俺代码如下,MLE过了,修改后一直 WA. 请帮我看一下,或者给几个case也好。 谢过了。 #include <stdio.h> #include <string.h> #include <stdlib.h> struct crim_t { crim_t() :boss(0), rev(0) {} int boss; // 该crim_t的比较者,即D 1 2,则 2.boss = 1, 2.rev = 1 int rev; // 1 表示该crim_t 与其 boss 不在同一团伙 }; const int N = 100001; crim_t crims[N]; int find(int x) { if (crims[x].boss == 0) return x; int xb = find(crims[x].boss); crims[x].boss = xb; crims[x].rev ^= crims[crims[x].boss].rev; return xb; } void union_(int x, int y) { int xb = find(x); int yb = find(y); if (xb != yb) { // 不加这个判断貌似 MLE crims[yb].boss = xb; crims[yb].rev = 1 ^ crims[y].rev ^ crims[x].rev; } } void answer(int x, int y) { int xp = find(x); int yp = find(y); if (xp == yp) { if (crims[x].rev == crims[y].rev) printf("In the same gang.\n"); else printf("In different gangs.\n"); } else printf("Not sure yet.\n"); } int main() { int t; scanf("%d", &t); for (int i = 0; i < t; ++i) { int n, m; scanf("%d%d", &n, &m); for (int j = 0; j < m; ++j) { char c; int x, y; scanf(" %c%d%d", &c, &x, &y); if (c == 'A') { if (n == 2) { // 只有两个crim_t,直接不在同一团伙 printf ("In different gangs.\n"); } else { answer(x, y); } } else union_(x, y); } memset(crims, 0, N); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator