-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler.cpp
42 lines (39 loc) · 807 Bytes
/
euler.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
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
int main() {
int M, N, a, b, odd = 0;
map<int, vector<int>> graph;
set<int> Set;
set<int> oddSet;
cin >> N >> M;
for (int i = 0; i < M; ++i) {
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
Set.insert(a);
Set.insert(b);
}
for (auto it: Set) {
if ((graph[it].size()%2) != 0) {
odd++;
oddSet.insert(it);
}
}
if (odd == 0) {
cout << "CYCLE" << endl;
}
else if (odd == 2) {
cout << "PATH";
for (auto it: oddSet) {
cout << " " << it;
}
cout << endl;
}
else {
cout << "IMPOSSIBLE" << endl;
}
return 0;
}