Nyoj (42) Eulerian graph

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.