Cod sursa(job #1467612)

Utilizator SilviuIIon Silviu SilviuI Data 3 august 2015 19:23:42
Problema Ciclu Eulerian Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <time.h>
#include <bitset>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <limits.h>
#include <algorithm>
#include <deque>
#define nmax 100010
#define mod 1999999973
#define eps 1e-12
using namespace std;
int n,m,i,j,x,y;
vector <int> g[nmax],sol;
stack <int> st;
int main() {
scanf("%d %d",&n,&m);
for (i=1;i<=m;i++) {
    scanf("%d %d",&x,&y);
    g[y].push_back(x); g[x].push_back(y);
}
st.push(1);
while (!st.empty()) {
    x=st.top();
    if (g[x].empty()) {
        sol.push_back(x); st.pop();
    } else
    {
        y=g[x][g[x].size()-1]; g[x].pop_back();
        st.push(y);
        g[y].erase(find(g[y].begin(),g[y].end(),x));
    }
}
for (i=0;i<sol.size();i++) printf("%d ",sol[i]);
return 0;
}