Cod sursa(job #1645851)

Utilizator felipeGFilipGherman felipeG Data 10 martie 2016 14:03:06
Problema Ciclu Eulerian Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define Nmax 100000
using namespace std;

ifstream is ("ciclueuler.in");
ofstream os ("ciclueuler.out");

int n, m;
vector < int > v[ Nmax ];

void citire ()
{
    int x, y;

    is >> n >> m;

    for ( int i = 1; i <= m; ++ i )
    {
        is >> x >> y;
        v[ x ].push_back( y );
        v[ y ].push_back( x );
    }
}

void DFS ( int nod )
{
    int aux = 0;

    for ( int i = 0; i < (int)v[ nod ].size(); ++ i )
    {
        aux = v[ nod ][ i ];

        v[ nod ].erase( v[ nod ].begin() + i );
        v[ aux ].erase( find( v[ aux ].begin(), v[ aux ].end(), nod ) );

        DFS( aux );
    }
    os << nod << " ";
}

int main()
{
    citire();
    DFS(1);
    return 0;
}