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 pb push_back
#define int long long
#define repp(i,x,n) for(int i=x;i<=n;i++)
#define repo(i,x,n) for(int i=x;i>=n;i--)
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define r0 return 0
#define fi first
#define se second
#define mp make_pair
#define liow ios_base::sync_with_stdio(false);cin.tie(NULL)
#define jelek cout<<"jelek"<<endl
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define pi pair<pair<int,int>,pair<int,int>>
#define p3 pair<int,pair<int,int>>
#define p4 pair<pii,pii>
#define fl fflush(stdout)
#define lb long double
using namespace std;
const int mod2=1e9+7,mod=998244353,maxn=5e5+5,N=(1<<17),INF=1e18;
vector<pii>adj[maxn];
bool visi[maxn];
vector<int>node;
int ej[maxn];
int deg[maxn];
void dfs(int x){
// cout<<"x "<<":"<<x<<endl;
node.pb(x);
visi[x]=1;
deg[x]--;
for(pii i :adj[x]){
if(ej[i.se]) continue;
if(visi[i.fi]){
// cout<<"anj ";
// for(int i=0;i<node.size();i++){
// cout<<node[i]<<" ";
// }
// cout<<endl;
int last=-1;
if(deg[i.fi]>0) last=i.fi;
while(!node.empty()){
cout<<node.back()<<" ";
visi[node.back()]=0;
if(last==-1) if(deg[node.back()]>0) last=node.back();
if(node.back()==i.fi){
node.pop_back();
break;
}
node.pop_back();
}
cout<<endl;
ej[i.se]=1;
if(last!=-1) dfs(last);
} else {
ej[i.se]=1;
deg[i.fi]--;
dfs(i.fi);
}
}
}
void solve(){
int n,m;cin>>n>>m;
repp(i,1,m){
int u,v;cin>>u>>v;
adj[u].pb({v,i});
adj[v].pb({u,i});
deg[u]++;
deg[v]++;
}
dfs(1);
}
signed main(){
liow;
int t=1;
// cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |