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 <iostream>
#include <vector>
using namespace std;
const int MAX_N = 5 * 1e5;
int in[MAX_N + 1], out[MAX_N + 1];
vector<int> g[MAX_N + 1], aux;
bool viz[MAX_N + 1], b[MAX_N + 1];
int n, m;
void dfs(int u) {
while(g[u].size()) {
int e=g[u].back();
g[u].pop_back();
if(viz[e])
continue;
viz[e]=1;
dfs(in[e]^out[e]^u);
aux.push_back(u);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> in[i] >> out[i];
in[i]--;
out[i]--;
g[in[i]].push_back(i);
g[out[i]].push_back(i);
}
aux.push_back(0);
dfs(0);
vector<int> sol;
for (int it : aux) {
if (b[it] == true) {
while (b[it] == true) {
cout << sol.back() + 1 << " ";
b[sol.back()] = false;
sol.pop_back();
}
cout << "\n";
}
b[it] = true;
sol.push_back(it);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |