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;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
set<int> adj[500010];
bool vis[500010];
vector<pii> p;
void dfs(int u)
{
while(!adj[u].empty())
{
int v=*adj[u].begin();
adj[u].erase(v);
adj[v].erase(u);
p.pb({u,v});
dfs(v);
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n,m;cin>>n>>m;
for(int i=0;i<m;i++)
{
int u,v;cin>>u>>v;
adj[u].insert(v);
adj[v].insert(u);
}
for(int i=1;i<=n;i++)
{
while(!adj[i].empty()) dfs(i);
}
stack<pii> st;
for(auto i : p)
{
st.push(i);
vis[i.fi]=1;
if(vis[i.se])
{
while(st.top().fi!=i.se)
{
cout<<st.top().fi<<' ';
vis[st.top().fi]=0;
st.pop();
}
cout<<i.se<<'\n';
vis[i.se]=0;
st.pop();
}
}
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... |