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; int p[100000]; int Find(int x) { int r, s; for (r = x; r != p[r]; r = p[r]); while (x != r) s = p[x], p[x] = r, x = s; return r; } void Union(int a, int b) { int ra, rb; ra = Find(a); rb = Find(b); if (ra == rb) return; p[rb] = ra; } int main() { int n, m, i, j, a, b, countV = 0; scanf("%d %d", &n, &m); for (i = 0; i < n + n; i++) p[i] = i; for (i = 0; i < m; i++) { scanf("%d %d %d", &j, &a, &b); if (j == 1) { if (a > n || b > n || Find(a - 1) == Find(b - 1 + n)) countV++; else Union(a - 1, b - 1), Union(a - 1 + n, b - 1 + n); } else { if (a > n || b > n || Find(a - 1) == Find(b - 1)) countV++; else Union(a - 1, b - 1 + n), Union(a - 1 + n, b - 1); } } printf("%d\n", countV); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator