#include <bits/stdc++.h>
using namespace std;
unordered_set<int> s[500005];
vector<int> a, b;
int inb[500005];
void dfs(int u)
{
while (s[u].size())
{
int v=*s[u].begin();
s[u].erase(v);
s[v].erase(u);
dfs(v);
}
a.push_back(u);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i=1; i<=m; i++)
{
int u, v;
cin >> u >> v;
s[u].insert(v);
s[v].insert(u);
}
dfs(1);
for (int u:a)
{
if (inb[u])
{
while (b.back()!=u)
{
cout << b.back() << ' ';
inb[b.back()]=0;
b.pop_back();
}
cout << u << '\n';
}
else
{
inb[u]=1;
b.push_back(u);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |