Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int v, e;
- set<int> adj[1001];
- void nhap (){
- cin >> v>> e;
- for (int i=1;i<=e;i++){
- int x,y;
- cin >> x>> y;
- adj[x].insert(y);
- adj[y].insert(x);
- }
- }
- void eulerCircle (int u ){
- stack < int > st;
- vector<int > EC;
- st.push(u);
- while ( !st.empty() ){
- int v= st.top();
- if ( adj[v].size()!=0 ){
- int first = *adj[v].begin();
- st.push(first);
- adj[v].erase(first);
- adj[first].erase(v);
- }
- else {
- st.pop();
- EC.push_back(v);
- }
- }
- for (auto x:EC) cout<<x<<" ";
- }
- int main(){
- nhap();
- eulerCircle(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment