Cod sursa(job #2551459)

Utilizator Alin_StanciuStanciu Alin Alin_Stanciu Data 19 februarie 2020 20:56:04
Problema Ciclu Eulerian Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

int n, m, depth;
vector<int> G[100001];
vector<pair<int, int>> M;
bool V[500001];

void Dfs(int x)
{
    ++depth;
    for (int i : G[x])
    {
        if (!V[i])
        {
            V[i] = true;
            Dfs(M[i].first == x ? M[i].second : M[i].first);
        }
    }
    --depth;
    if (depth != 0)
        fout << x << " ";
}

int main()
{
    fin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int x, y;
        fin >> x >> y;
        M.emplace_back(x, y);
        G[x].push_back(M.size() - 1);
        G[y].push_back(M.size() - 1);
    }
    Dfs(1);

    return 0;
}