Cod sursa(job #2399930)

Utilizator Andrei0308Andrei Loghin Andrei0308 Data 8 aprilie 2019 10:37:03
Problema Ciclu Eulerian Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;
ifstream fin ("ciclueuler.in");
ofstream fout ("ciclueuler.out");

int n, nr, m;
int start1;

int L[5000];
int A[250][250];

void citire();
void Euler(int);

int main()
{
    citire();
    start1 = 1;
    Euler(start1);

    for(int i=1; i < nr; i++)
        fout<<L[i]<<' ';
    return 0;
}

void citire()
{
    int x, y;

    fin>>n>>m;
    for(int i=1; i <= m; i++)

    {
        fin>>x>>y;
        A[x][y]++;
        A[y][x]++;
    }
}

void Euler(int k)
{
    for(int i = 1 ; i <= n ; i ++)
        if(A[k][i])
        {
            A[k][i]--;
            A[i][k]--;
            Euler(i);
        }
    L[++nr] = k;
}