| ||||||||||
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#include<iostream> using namespace std; #define MAX 1000020 int father[MAX]; int rank[MAX]; void make_set(int x) { father[x] = x; rank[x] = 0; } int find_set(int x) { if(x != father[x]) father[x] = find_set(father[x]); return father[x]; } void union_set(int x, int y) { int r1, r2; r1 = find_set(x); r2 = find_set(y); if(r1 == r2) return ; if(rank[r1] < rank[r2]) father[r1] = r2; else { if(rank[r1] == rank[r2]) rank[r1] ++; father[r2] = r1; } } int main() { int i, j, t, num, m; int a, b; int r1, r2; scanf("%d", &t); for(j = 1; j <= t; j ++) { int flag = 0; scanf("%d%d", &num, &m); for(i = 1; i <= num; i ++) make_set(i); for(i = 1; i <= m; i ++) { scanf("%d%d", &a, &b); if(flag == 1) continue; r1 = find_set(a); r2 = find_set(b); if(r1 != r2) union_set(r1, r2); else { flag = 1; //break; } } printf("Scenario #%d:\n", j); if(flag) printf("Suspicious bugs found!\n\n"); else printf("No suspicious bugs found!\n\n"); } system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator