# PAT | A1126 Eulerian Path

#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <queue>

using namespace std;

bool G[510][510];
int degree[510];
unordered_set<int> connect;
bool vis[510];

void BFS(int i,int n){
fill(vis,vis + 510,false);
queue<int> q;
q.push(i);
while(!q.empty()){
int u = q.front();
q.pop();
connect.insert(u);
for(int j = 1;j <= n;j++){
if(G[u][j] == true && vis[j] == false){
q.push(j);
vis[j] = true;
}
}
}
}

int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i = 0;i < 510;i++)
for(int j = 0;j < 510;j++)
G[i][j] = false;
for(int i = 0;i < m;i++){
int u,v;
scanf("%d%d",&u,&v);
G[u][v] = G[v][u] = true;
}
fill(degree,degree + 510,0);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(G[i][j] == true)
degree[i]++;
}
}
int odd = 0;
for(int i = 1;i <= n;i++){
printf("%d",degree[i]);
if(i != n)
printf(" ");
else
printf("\n");
if(degree[i] % 2 != 0)
odd++;
}
BFS(1,n);
if(odd > 2 || odd == 1 || connect.size() < n){
printf("Non-Eulerian");
}else if(odd == 2){
printf("Semi-Eulerian");
}else{
printf("Eulerian");
}
system("pause");
return 0;
}


©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客