Cod sursa(job #2175401)

Utilizator BotzkiBotzki Botzki Data 16 martie 2018 17:00:40
Problema Ciclu Eulerian Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
ifstream fin("euler.in");
ofstream fout("euler.out");
const int NMAX=100000;
int n, m, node;
bool use[NMAX+5];
vector<int>G[NMAX+5];
stack<int>st;
void euler(int node)
{
    while(!G[node].empty())
    {
        st.push(node);
        int other=G[node].back();
        G[node].pop_back();
        G[other].erase(find(G[other].begin(), G[other].end(), node));
        node=other;
    }
}
int main()
{
    int i, x, y;
     fin>>n>>m;
     for(i=1;i<=m;i++)
     {
         fin>>x>>y;
         G[x].push_back(y);
         G[y].push_back(x);
     }
     node=1;
     do
     {
        euler(node);
        node=st.top();
        fout<<node<<" ";
        st.pop();
     }while(!st.empty());
    return 0;
}