Title Link: http://acm.nyist.net/JudgeOnline/problem.php?pid=42
I was referring to the Red and Black Alliance's Knot report. But there is a place where the red and black league should be wrong, that is the definition of connectivity here.
Euler's theorem:
1, the figure is connected, every two points to be directly or indirectly connected. (The red and Black league seems to have written it wrong)
2, the singularity sum can only be 0 or 2;
The DFS here is very ingenious, I am here WA, DFS (k), if you find an edge, but only increase the degree of K, because after Dfs (i), plus the degree of I, and will not access K this point.
Then, the sail brother taught me directly in the construction of the map when the degree of each point to write well on it. Very convenient. Two copies of the code are affixed.
#include <stdio.h>#include<string.h>BOOLmaps[1010][1010];BOOLvis[1010];intdegree[1010];intn,m;voidDfsintk) {Vis[k]=true; for(intI=1; i<=n;i++) { if(Maps[k][i]) {Degree[k]++; if(!Vis[i]) DFS (i); } }}intMain () {intT; scanf ("%d",&t); while(t--) {memset (Vis,false,sizeof(VIS)); memset (Maps,false,sizeof(maps)); memset (degree,0,sizeof(degree)); scanf ("%d%d",&n,&m); intx, y; for(intI=0; i<m;i++) {scanf ("%d%d",&x,&y); Maps[x][y]= Maps[y][x] =true; } DFS (1); BOOLFlag =true; for(intI=1; i<=n;i++) { if(!Vis[i]) {Flag=false; Break; } } if(!flag) printf ("no\n"); Else { intAns =0; for(intI=1; i<=n;i++) { if(degree[i]%2) ans++; } if(ans==0|| ans==2) printf ("yes\n"); Elseprintf"no\n"); } } return 0;}
#include <stdio.h>#include<string.h>BOOLmaps[1010][1010];BOOLvis[1010];intdegree[1010];intn,m;voidDfsintk) {Vis[k]=true; for(intI=1; i<=n;i++) { if(Maps[k][i]) {if(!Vis[i]) DFS (i); } }}intMain () {intT; scanf ("%d",&t); while(t--) {memset (Vis,false,sizeof(VIS)); memset (Maps,false,sizeof(maps)); memset (degree,0,sizeof(degree)); scanf ("%d%d",&n,&m); intx, y; for(intI=0; i<m;i++) {scanf ("%d%d",&x,&y); Maps[x][y]= Maps[y][x] =true; DEGREE[X]++; Degree[y]++; } DFS (1); BOOLFlag =true; for(intI=1; i<=n;i++) { if(!Vis[i]) {Flag=false; Break; } } if(!flag) printf ("no\n"); Else { intAns =0; for(intI=1; i<=n;i++) { if(degree[i]%2) ans++; } if(ans==0|| ans==2) printf ("yes\n"); Elseprintf"no\n"); } } return 0;}
Nyoj (42) Eulerian graph