#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<set<int>> graph(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--; b--;
graph[a].insert(b);
graph[b].insert(a);
}
//dont need to check if possible bc question says is possible
for (int i = 0; i < n; i++) { //for every vertex
while (graph[i].size() > 0) { //whilst tours can start from here
vector<set<int>> g = graph; //so not remove all edges forever
vector<int> seq;
stack<int> stak;
stak.push(i);
while (!stak.empty()) {
int u = stak.top();
//~ cout << u+1 << endl;
if (g[u].size() > 0) { //if still neighbours
int v = *g[u].begin();
stak.push(v);
g[u].erase(v); //erase edge from both sides
g[v].erase(u);
} else { //need to add to tour
stak.pop();
seq.push_back(u);
//~ cout << u+1 << " ";
}
}
reverse(seq.begin(), seq.end());
//~ cout << "seq " ;
//~ for (int i : seq) {
//~ cout << i+1 << " ";
//~ }
//~ cout << endl;
//now make sure no vertices visited multiple times
auto it = seq.begin()+1;
vector<int> ans;
ans.push_back(seq[0]);
while (it < seq.end()) {
//~ cout << *it+1;
ans.push_back(*it);
auto next = find(it+1, seq.end(), *it);
if (next < seq.end()) { //if this knot occurs again
it = next;
//~ cout << " " << *it+1;
}
cout << endl;
it++;
}
int prev = -1;
//~ cout << endl;
for (int x : ans) {
cout << x+1 << " ";
if (prev != -1) { //removal of edges used
graph[prev].erase(x);
graph[x].erase(prev);
}
prev = x;
}
cout << endl;
}
}
}
//ES GIBT KEINE MOEGLICHEN EULER TOUREN< WARUMMMMMMM
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Some edges were not used |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Some edges were not used |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Some edges were not used |
2 |
Halted |
0 ms |
0 KB |
- |