-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEulerian Path.cpp
77 lines (74 loc) · 1.37 KB
/
Eulerian Path.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
int edage[510][510];
int visited[510] = {0};
int n;
int degree[510];
int dfs(int v)
{
visited[v] = 1;
int sum = 0;
for (int i = 1; i < n + 1; i++)
{
if (edage[v][i] == 1)
sum++;
}
degree[v] = sum;
for (int i = 1; i < n + 1; i++)
{
if (visited[i] == 0 && edage[i][v] == 1)
dfs(i);
}
return 0;
}
int main()
{
for (int i = 0; i < 510; i++)
{
for (int j = 0; j < 510; j++)
{
edage[i][j] = 0;
}
}
int m;
std::cin >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y;
std::cin >> x >> y;
edage[x][y] = 1;
edage[y][x] = 1;
}
int sum = 0;
for (int i = 1; i < n + 1; i++)
{
if (visited[i] == 0)
{
dfs(i);
sum++;
}
}
for (int i = 0; i < 510; i++)
{
visited[i] = 0;
}
int odd = 0;
for (int i = 1; i < n + 1; i++)
{
std::cout << degree[i];
if (degree[i] % 2 == 1)
odd++;
if (i != n)
std::cout << " ";
else
{
std::cout << std::endl;
}
}
if (odd == 0 && sum == 1)
std::cout << "Eulerian";
else if (odd == 2 && sum == 1)
std::cout << "Semi-Eulerian";
else
std::cout << "Non-Eulerian";
return 0;
}