标签:return printf ini include mis pst 一句话 script des
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 66294 | Accepted: 19539 |
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
Source
#include<stdio.h> int father[51010],relation[51010]; void init(int n) { int i; for(i=1;i<=n;++i) father[i]=i; for(i=1;i<=n;++i) relation[i]=0; } int find(int x) { if(x==father[x]) return (x); int t=father[x]; father[x]=find(father[x]); relation[x]=(relation[x]+relation[t])%3; return (father[x]); } void merge(int x,int y,int z) { int find_x=find(x); int find_y=find(y); if(find_x!=find_y) { relation[find_x]=(z-1+relation[y]-relation[x]+3)%3; father[find_x]=find_y; } } int main() { int n,m,relat,x,y,ans=0; scanf("%d%d",&n,&m); init(n); while(m--) { scanf("%d%d%d",&relat,&x,&y); if(x>n||y>n||(relat==2&&x==y)) { ++ans; continue; }else if(find(x)!=find(y)) { merge(x,y,relat); continue; }else if(find(x)==find(y)) { if(relat==1) { if(relation[x]!=relation[y]) { ++ans; continue; } }else if(relat==2) { if((relation[x]-relation[y]+3)%3!=1) { ++ans; continue; } } } } printf("%d\n",ans); return 0; }
标签:return printf ini include mis pst 一句话 script des
原文地址:http://www.cnblogs.com/fuermowei-sw/p/6193521.html