Repository navigation
Expand file tree
/
Copy pathThe_Islander.cpp
More file actions
94 lines (76 loc) · 1.98 KB
/
Copy pathThe_Islander.cpp
File metadata and controls
94 lines (76 loc) · 1.98 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
const int N = 100000;
const int M = 100000;
int degree[N];
bool visited[N];
vector<int> graph[N];
int vertexCount, edgesCount;
void dfs(int v) {
visited[v] = true;
for (auto x : graph[v]) {
if (visited[x] == false) {
dfs(x);
}
}
}
bool isConnected() {
for (int i = 0; i < vertexCount; i++) {
for (int k = 0; k < vertexCount; k++) {
visited[k] = false;
}
dfs(i);
for (int j = 0; j <vertexCount; j++) {
if (visited[j] == false) {
return false;
}
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int queriesCount;
cin >> queriesCount;
for (int i = 0; i < queriesCount; i++) {
cin >> vertexCount >> edgesCount;
for (int i = 0; i < N; i++) {
degree[i] = 0;
}
for (int i = 0; i < edgesCount; i++) {
int from, to;
cin >> from >> to;
degree[from]++;
degree[to]++;
graph[from].push_back(to);
graph[to].push_back(from);
}
int oddDegreeCount = 0;
for (int i = 0; i < N; i++) {
if (degree[i] % 2 != 0) {
oddDegreeCount++;
}
}
if (isConnected() || oddDegreeCount==0) {
if (oddDegreeCount == 0) {
cout << "ecycle\n";
}
else if (oddDegreeCount==0 || oddDegreeCount == 2) {
cout << "epath\n";
}
else {
cout << "none\n";
}
}
else {
cout<<"none\n";
}
for(int i=0;i<N;i++){
graph[i].clear();
visited[i]=false;
}
}
return 0;
}