Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 55576 | Accepted: 16297 |
Description
Input
Output
Sample Input
100 7 1 101 1 2 1 2 2 2 3 2 3 3 1 1 3 2 3 1 1 5 5
Sample Output
3 这个题PIJ只有一组测试数据,醉醉的...wa了惨不忍睹。。。 ac代码:#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #define fab(a) (a)>0?(a):(-a) #define LL long long #define MAXN 100010 #define mem(x) memset(x,0,sizeof(x)) #define INF 0xfffffff #define PI acos(-1.0) using namespace std; int pri[MAXN]; int rist[MAXN]; int find(int x) { if(pri[x]==x) return x; int temp=pri[x]; pri[x]=find(temp); rist[x]=(rist[x]+rist[temp])%3; return pri[x]; } int main() { int n,m,i,a,b,c; scanf("%d%d",&n,&m); int ans=0; for(i=1;i<=n;i++) pri[i]=i,rist[i]=0; while(m--) { scanf("%d%d%d",&c,&a,&b); if(a>n||b>n) { ans++; continue; } if(c==2&&a==b) { ans++; continue; } int nx=find(a); int ny=find(b); if(nx!=ny) { pri[ny]=nx; rist[ny]=(3+(c-1)+rist[a]-rist[b])%3; } else { if(c==1&&rist[a]!=rist[b]) ans++; if(c==2&&rist[a]!=(rist[b]+2)%3) ans++; } } printf("%d\n",ans); return 0; }