Cod sursa(job #1613291)

Utilizator felipeGFilipGherman felipeG Data 25 februarie 2016 12:02:10
Problema Ciclu Eulerian Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define N 100000
using namespace std;

ifstream f ("ciclueuler.in");
ofstream g ("ciclueuler.out");

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

void citire()
{
    int x, y;

    f >> n >> m;

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

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

   //g << nod << " ";

   for ( i = 0; i < 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 );
   }
   g << nod << " ";
}

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