pat-1126

I turned out to be like an Indian electrician. I used it to make a statement. It was very messy and easy to poke. Now I am a German electrician hahahaha~ 

#include<iostream>
#include<vector>
using namespace std;
vector<int>nume[509];//记录度数出边数 
int visit[509]={0},cnt=0;//记录是否访问过q 
//判断是否连通,看看顶点数是多少,自然不能有重复访问顶点的情况
//cnt 1 
// cnt 不能固定在参数列表考虑到递归对return 的影响还是写无返回值函数(注意) 
void dfs(int index)
{//End
cnt++;
visit[index]=1;
for(int i=0;i<nume[index].size();i++)
if(visit[nume[index][i] ]==0)
 dfs(nume[index][i]);
  
}
int main()
{ int n,m,_1,_2,even=0,t=1;
cin>>n>>m;
for(int i=0;i<m;i++)
{   cin>>_1>>_2;
	nume[_1].push_back(_2);
	nume[_2].push_back(_1);
}
for(int i=1;i<=n;i++)
{
if(i!=1) printf(" ");
printf("%d",nume[i].size());
if(nume[i].size()%2==0) even++;
}
printf("\n");
dfs(1) ;
if(cnt!=n) printf("Non-Eulerian\n");
else if(even==n) printf("Eulerian\n");
else if(even==n-2) printf("Semi-Eulerian\n");
else printf("Non-Eulerian\n");
return 0;
}

to sum up

1. dfs try not to have a return value, because the recursive process will affect him and return

2. Pay attention to directly copy the number of nodes information to prevent mistakes

3. Judging whether the connection is not connected here is a good example

English

 

Summarize the printing path of the DFS tree last time popback has not been resolved

The difference from the previous path problem is that the last time the set mark was saved in the path, this time the mark is set as long as it has been accessed and cannot be deleted.

 

 

 

Guess you like

Origin blog.csdn.net/m0_45359314/article/details/112803135