#include <bits/stdc++.h>
#define NMAX 500000
#define LOG 19
#define ll long long int
#define BASE 128
#define MOD 998244353
using namespace std;
ifstream fin("cod.in");
ofstream fout("cod.out");
int vis[NMAX+1];
vector<pair<int,int>> adj[NMAX+1];
bool used[NMAX+1];
vector<int> euler;
void dfs(int x,int t)
{
for(auto [y,id] : adj[x])
{
if(!used[id])
{
used[id]=1;
dfs(y,t);
}
}
euler.push_back(x);
}
int last[NMAX+1];
int main()
{
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++)
{
int x,y;
cin >> x >> y;
adj[x].push_back({y,i});
adj[y].push_back({x,i});
}
dfs(1,0);
for(int i : euler)
{
cout << i << " ";
}
cout << '\n';
vector<int> st;
for(int i : euler)
{
if(last[i])
{
vector<int> v;
v.push_back(i);
while(st.back()!=i)
{
last[st.back()]--;
v.push_back(st.back());
st.pop_back();
}
v.push_back(i);
st.pop_back();
last[i]--;
for(int j : v)
{
cout << j << " ";
}
cout << '\n';
}
st.push_back(i);
last[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... |