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>
#include <set>
#define MAXN 500001
using namespace std;
set<int> adj_lst[MAXN];
vector<int> euler;
vector<int> str;
int check[MAXN];
void find(int u){
euler.push_back(u);
//cerr<<u<<" ";
while( (int)adj_lst[u].size() ){
int x = *adj_lst[u].begin();
adj_lst[u].erase(x);
adj_lst[x].erase(u);
find(x);
}
str.push_back(u);
euler.pop_back();
}
int degree[MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nodes, edges;
cin>>nodes>>edges;
while( edges-- ){
int u, v;
cin>>u>>v;
adj_lst[u].insert(v);
adj_lst[v].insert(u);
++degree[u]; ++degree[v];
}
//cout<<l<<" "<<r<<" "<<poss<<'\n';
//adj_lst[l].insert(r); adj_lst[r].insert(l);
find(1);
vector<int> curr;
//for( int i{(int)str.size()-1} ; i >= 0 ; --i ) cout<<str[i]<<" "; cout<<'\n';
while( !str.empty() ){
int u = str.back();
str.pop_back();
if( check[u] ){
//cerr<<u<<'\n';
cout<<u<<" ";
while( curr.back() != u && !curr.empty() ) cout<<curr.back()<<" ", check[curr.back()] = 0, curr.pop_back();
//nw.push_back(u);
cout<<'\n';
//for( int x : nw ) cerr<<x<<" "; cerr<<'\n';
}
else{
check[u] = 1;
curr.push_back(u);
}
}
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... |