This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m;
set<int> G[N];
vector<int> euler;
bool visit[N];
void dfs(int u) {
while (G[u].size()) {
int v = *G[u].begin();
G[u].erase(G[u].begin()), G[v].erase(G[v].find(u));
dfs(v);
}
euler.push_back(u);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int u, v; cin >> u >> v;
G[u].insert(v), G[v].insert(u);
}
dfs(1);
vector<int> vCur;
for (auto i : euler) {
if (visit[i]) {
vector<int> vNew;
vNew.push_back(i);
cout << i << ' ';
while (vCur.back() != i) {
int tmp = vCur.back();
cout << tmp << ' ';
visit[tmp] = 0, vCur.pop_back();
}
cout << '\n';
} else {
vCur.push_back(i), visit[i] = 1;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |