标签:continue flag printf 判断 ons ota can tin NPU
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20997 Accepted Submission(s): 8152
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n,m; 5 const int N=1005; 6 int G[N][N]; 7 int degree[N]; 8 int fa[N]; 9 10 void init(){ 11 memset(G,0,sizeof G); 12 memset(degree,0,sizeof degree); 13 for(int i=1;i<N;i++){ 14 fa[i]=i; 15 } 16 } 17 18 int find(int x){ 19 while(x!=fa[x]){ 20 x=fa[x]; 21 } 22 return x; 23 } 24 25 void Union(int x,int y){ 26 int fx=find(x),fy=find(y); 27 if(fx!=fy){ 28 fa[fx]=fy; 29 } 30 } 31 32 int main(){ 33 int x,y; 34 while(cin>>n,n){ 35 cin>>m; 36 init(); 37 for(int i=0;i<m;i++){ 38 scanf("%d%d",&x,&y); 39 if(G[x][y]==0&&G[y][x]==0){ 40 G[x][y]=G[y][x]=1; 41 degree[x]++; 42 degree[y]++; 43 Union(x,y); 44 } 45 } 46 int flag=1; 47 int rt=find(1); 48 for(int i=2;i<=n;i++){ 49 if(find(i)!=rt){ 50 flag=0; 51 break; 52 } 53 } 54 if(flag==0){ 55 printf("%d\n",flag); 56 continue; 57 } 58 for(int i=1;i<=n;i++){ 59 if(degree[i]%2==1){ 60 flag=0; 61 break; 62 } 63 } 64 printf("%d\n",flag); 65 } 66 }
标签:continue flag printf 判断 ons ota can tin NPU
原文地址:https://www.cnblogs.com/ChangeG1824/p/11664037.html