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 |
Re:几组测试数据In Reply To:几组测试数据 Posted by:wanghaishanren at 2008-04-30 19:40:11 上面的都过了,vijos也ac了,交上去还WA,无语。。。。。那个大牛帮下 #include<iostream> using namespace std; int fa[500001], flag[500001]; void Initset(int n) { for (int i = 1; i <= n; i++) { fa[i] = i; flag[i] = 0; } } int find(int x) { int t = fa[x]; if (fa[x] != x) { fa[x] = find(fa[x]); flag[x] = (flag[x] + flag[t] + 1) % 3 - 1; } return fa[x]; } int unin(int a, int x, int y) { int m = find(x), n = find(y); if (m == n) { if ((flag[x] - flag[y] + 3) % 3 != a - 1)return 1; } else fa[m] = n, flag[m] = (flag[y] - flag[x] + a) % 3 - 1; return 0; } int main() { int n, k, a, x, y, re; while (cin >> n >> k) { Initset(n); re = 0; while (k--) { cin >> a >> x >> y; if (x > n || y > n || (a == 2 && x == y) || unin(a, x, y)) re++; } cout << re << endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator