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>
#define long long long
using namespace std;
const int V = (int) 5E5;
const int E = (int) 5E5;
int n, m;
vector<pair<int, int>> e[V];
int t[E];
int c[V];
vector<int> a;
void DFS(int u) {
while (e[u].empty() == 0) {
int v, i;
tie(v, i) = e[u].back();
e[u].pop_back();
if (t[i] == 0) {
t[i] = 1;
DFS(v);
}
}
a.push_back(u);
c[u] = c[u] + 1;
if (c[u] > 1) {
cout << u + 1 << " ";
c[u] = c[u] - 1;
a.pop_back();
while (a.back() != u) {
cout << a.back() + 1 << " ";
c[a.back()] = c[a.back()] - 1;
a.pop_back();
}
cout << "\n";
}
}
void solve() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u = u - 1, v = v - 1;
e[u].push_back({v, i});
e[v].push_back({u, i});
}
DFS(0);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int t;
t = 1;
for (int i = 0; i < t; i++) {
solve();
}
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... |