Cod sursa(job #2171636)

Utilizator andreiutu111Noroc Andrei Mihail andreiutu111 Data 15 martie 2018 12:59:33
Problema Ciclu Eulerian Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include<bits/stdc++.h>
using namespace std;
int N,M,x,y;
vector <int> G[100001],st;
int main()
{
    freopen("ciclueuler.in","r",stdin);
    freopen("ciclueuler.out","w",stdout);
    scanf("%d%d",&N,&M);
    while(M--){
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    st.push_back(1);
    while(!st.empty()){
        int nod=st.back();
        if(G[nod].size()){
            y=G[nod].back();
            G[nod].pop_back();
            G[y].erase(find(G[y].begin(),G[y].end(),nod));
            st.push_back(y);
        }else{
            printf("%d ",nod);
            st.pop_back();
        }
    }
    return 0;
}