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 |
大神帮忙看一下,这有什么问题,为什么就是通不过#include<stdio.h> #define N 50000 int st[N+100]; int rank[N+100]; int count; int find(int i) { if(st[i]==i) return i; st[i]=find(st[i]); rank[i]=(rank[i]+rank[st[i]])%3; return st[i]; } void unionset(int i,int j,int d) { int tp,tq; tp=find(i); tq=find(j); if(tp==tq){ if((rank[j]-rank[i]+3)%3!=d) count++; return ; } st[tq]=tp; rank[tq]=(rank[i]-rank[j]+3+d)%3; return ; } int main(void) { int i,n,m; int d,x,y; scanf("%d%d",&n,&m); count=0; for(i=0;i<n;i++){ st[i]=i; rank[i]=0; } for(;m>0;m--){ scanf("%d%d%d",&d,&x,&y); if(x>n||y>n) { count++; continue; } unionset(x,y,d-1); } printf("%d\n",count); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator