Cod sursa(job #1923379)

Utilizator DragosCDragos Corleanca DragosC Data 10 martie 2017 23:22:54
Problema Ciclu Eulerian Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#define nmax 100001
#define mmax 500001
using namespace std;
int n,m;
vector<int> graf[nmax];
stack<int> st;
struct muchii
{
    int x,y;
    bool del=0;
}v[mmax];

void ciclu()
{
    ofstream g("ciclueuler.out");
    st.push(1);
    while(!st.empty())
    {
        int topp=st.top();
        if(graf[topp].size())
        {
            int next=graf[topp].back();
            graf[topp].pop_back();
            if(v[next].del)
                continue;
            v[next].del=1;
            if(v[next].x==topp)
                st.push(v[next].y);
            else st.push(v[next].x);
        }
        else
        {
            g<<st.top()<<" ";
            st.pop();
        }
    }
}

int main()
{

    ifstream f("ciclueuler.in");

    f>>n>>m;
    for(int i=1;i<=m;i++)
    {
        f>>v[i].x>>v[i].y;
        graf[v[i].x].push_back(i);
        graf[v[i].y].push_back(i);
    }
    ciclu();
    return 0;
}