Cod sursa(job #2173283)

Utilizator cubaLuceafarul cuba Data 15 martie 2018 21:29:31
Problema Ciclu Eulerian Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
const int nMax = 100005;
int st[nMax * 5], dr[nMax * 5];
bool viz[nMax];
vector <int> G[nMax], ans;
inline void Dfs(int nod) {
    for(const auto &v :  G[nod]){
        if(!viz[v]) {
            viz[v] = 1;
            Dfs(st[v] + dr[v] - nod);
        }
    }
    ans.push_back(nod);
}
int main()
{
    int n, m, x, y;
    f >> n >> m;
    for(int i = 1; i <= m; i++) {
        f >> st[i] >> dr[i];
        G[st[i]].push_back(i);
        G[dr[i]].push_back(i);
    }
    for(int i = 1; i <= n; i++) {
        if(G[i].size() % 2 == 1) {
            g << "-1\n";
            return 0;
        }
    }
    Dfs(1);
    for(const auto &x : ans) {
        g << x << " ";
    }
    return 0;
}