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;
int n, m, u, v;
vector<queue<pair<int, int>>> adj;
vector<int> res;
vector<bool> sus;
void euler(int s) {
while (!adj[s].empty()) {
int e = adj[s].front().first;
int i = adj[s].front().second;
adj[s].pop();
if (!sus[i]) { sus[i] = true; euler(e); }
sus[i] = true;
}
res.push_back(s);
}
int main() {
cin >> n >> m;
adj.resize(n);
sus.resize(m);
vector<int> deg(n);
int g = 0;
for (int i = 0; i < m; i++) {
cin >> u >> v;
adj[u-1].push({v-1, g});
adj[v-1].push({u-1, g++});
}
euler(0);
reverse(res.begin(), res.end());
vector<int> vst(n, -1);
vector<int> nxt(n, -1);
for (int i = 0; i < res.size(); i++) {
int node = res[i];
if (vst[node] == -1) {
vst[node] = i;
nxt[node] = res[i+1];
}
else {
int nd = res[vst[node]];
do {
cout << nd+1 << ' ';
vst[nd] = -1;
nd = nxt[nd];
} while (nd != node);
cout << '\n';
nxt[node] = res[i+1];
vst[node] = i;
}
}
}
Compilation message (stderr)
postmen.cpp: In function 'int main()':
postmen.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < res.size(); i++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |