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;
int eulertour[1000000];
int ptr = 0;
set<int> adjlist[500000];
void deleteEdge(int a, int b){
adjlist[a].erase(b);
adjlist[b].erase(a);
}
void tour(int node){
while (adjlist[node].size()>0){
int newnode = *adjlist[node].begin();
deleteEdge(node, newnode);
tour(newnode);
}
eulertour[ptr]=node;
ptr++;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n,m;
cin>>n>>m;
//adjlist.resize(n);
for (int i = 0; i<m; i++){
int a,b;
cin>>a>>b;
a--;b--;
adjlist[a].insert(b);
adjlist[b].insert(a);
}
tour(0);
stack<int> proc;
bool visited[500000];
for (int i = 0; i<n; i++){
visited[i]=0;
}
for (int ix = 0; ix<ptr; ix++){
int i = eulertour[ix];
if (visited[i]){
cout<<i+1<<' ';
while (proc.size()>0&&proc.top()!=i){
cout<<proc.top()+1<<' ';
visited[proc.top()]=false;
proc.pop();
}
cout<<'\n';
} else {
visited[i]=true;
proc.push(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... |