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 int long long
vector<pair<int,int> >adj[500002];
int sz[500002];
bool edge[500002];
bool node[500002];
vector<int>ans;
vector<int>simpan;
void dfs(int q){
if(node[q]==true){
while(!ans.empty()){
int tmp=ans.back();
if(tmp==q){
cout<<q<<endl;
break;
}
else{
cout<<tmp<<" ";
node[tmp]=false;
ans.pop_back();
}
}
}
else{
ans.push_back(q);
}
node[q]=true;
for(auto r : adj[q]){
if(edge[r.second]==false){
edge[r.second]=true;
sz[q]--;
sz[r.first]--;
dfs(r.first);
break;
}
}
}
signed main(){
int n,m;
cin>>n>>m;
int cnt=1;
for(int q=1;q<=m;q++){
int u,v;
cin>>u>>v;
sz[u]++;
sz[v]++;
adj[u].push_back({v,cnt});
adj[v].push_back({u,cnt});
cnt++;
}
for(int q=1;q<=n;q++){
if(sz[q]>0){
memset(node,false,sizeof node);
dfs(q);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |