标签:输出 col 并查集 rip port target ssi sea about
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1829
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18563 Accepted Submission(s): 5931
#include<bits/stdc++.h> using namespace std; #define max_v 2005 int pa[max_v]; int re[max_v]; int flag; void make_set(int x) { pa[x]=x; re[x]=0; } int find_set(int x) { if(x==pa[x]) return pa[x]; int t=find_set(pa[x]); re[x]=(re[pa[x]]+re[x])%2; pa[x]=t; return pa[x]; } void union_set(int x,int y) { int a=find_set(x); int b=find_set(y); if(a==b) { if(re[x]==re[y]) flag=1; return ; } pa[a]=b; re[a]=(re[x]-re[y]+3)%2; } int main() { int t,j=1; scanf("%d",&t); while(t--) { int n,m; scanf("%d %d",&n,&m); flag=0; for(int i=1;i<=n;i++) make_set(i); for(int i=0;i<m;i++) { int a,b; scanf("%d %d",&a,&b); if(flag==1) continue; union_set(a,b); } printf("Scenario #%d:\n",j++); if(flag==1) printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); printf("\n"); } return 0; } /* 种类 :2种 */#include<bits/stdc++.h> using namespace std; #define max_v 2005 int pa[max_v]; int re[max_v]; int flag; void make_set(int x) { pa[x]=x; re[x]=0; } int find_set(int x) { if(x==pa[x]) return pa[x]; int t=find_set(pa[x]); re[x]=(re[pa[x]]+re[x])%2; pa[x]=t; return pa[x]; } void union_set(int x,int y) { int a=find_set(x); int b=find_set(y); if(a==b) { if(re[x]==re[y]) flag=1; return ; } pa[a]=b; re[a]=(re[x]-re[y]+3)%2; } int main() { int t,j=1; scanf("%d",&t); while(t--) { int n,m; scanf("%d %d",&n,&m); flag=0; for(int i=1;i<=n;i++) make_set(i); for(int i=0;i<m;i++) { int a,b; scanf("%d %d",&a,&b); if(flag==1) continue; union_set(a,b); } printf("Scenario #%d:\n",j++); if(flag==1) printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); printf("\n"); } return 0; } /* 种类 :2种 */
标签:输出 col 并查集 rip port target ssi sea about
原文地址:https://www.cnblogs.com/yinbiao/p/9198599.html