Cod sursa(job #2815452)

Utilizator oporanu.alexAlex Oporanu oporanu.alex Data 9 decembrie 2021 17:31:43
Problema Ciclu Eulerian Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int nmax = 100005;
vector<int> cycle;
vector<int> adj[nmax];
void euler(int vertex){
    while(adj[vertex].empty() == false)
    {
        int ngb = adj[vertex][adj[vertex].size() - 1];
        adj[vertex].pop_back();
        adj[ngb].pop_back();
        euler(ngb);
    }
    cycle.push_back(vertex);

}
int main()
{
    int V, E;
    fin >> V >> E;
    for(int i = 1; i <= E; ++i){
        int src, dst;
        fin >> src >> dst;
        adj[src].push_back(dst);
        adj[dst].push_back(src);
    }

    euler(1);
    for(auto el: cycle){
        fout << el << ' ';
    }
    return 0;
}