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 <stdio.h> int father[50010], relate[50010]; void makeset(int n) { int i; for(i=1;i<=n;++i) { father[i]=i; relate[i]=0; } } int findset(int x) { int t; if(x!=father[x]) { t=father[x]; father[x]=findset(father[x]); relate[x]=(relate[x]+relate[t])%3; } return father[x]; } void Union(int x, int y, int relat) { int xx, yy; xx=findset(x); yy=findset(y); father[yy]=xx; relate[yy]=(relate[x]-relate[y]+relat+3)%3; } int main() { int N, K, tag, ai ,bi, sum=0, aai, bbi; makeset(N); while(K--) { scanf("%d%d%d", &tag, &ai, &bi); if(ai>N||bi>N||(tag==2&&ai==bi)) { ++sum; } else { aai=findset(ai); bbi=findset(bi); if((aai==bbi)&&(relate[ai]-relate[bi]+3)%3!=tag-1) { ++sum; } else Union(ai, bi, tag); } } printf("%d\n", sum); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator