Cod sursa(job #2560741)

Utilizator PatrascuAdrian1Patrascu Adrian Octavian PatrascuAdrian1 Data 28 februarie 2020 11:14:28
Problema Ciclu Eulerian Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("t.in");
ofstream out("t.out");

const int Nmax = 1e5 + 5;
bool vis[Nmax];
stack <int> S;
vector <int> G[Nmax];

void dfs(int node) {
    S.push(node);
    while(!S.empty()) {
        int x = S.top();
        if(G[x].empty()) {
            ans.push_back(x);
            S.pop();
        } else {
            int y = G[x].back();
            G[x].pop_back();
            S.push(y);
            G[y].erase(find(G[y].begin(),G[y].end(),x));
        }
    }
}
int main() {
    int N,M;
    in >> N >> M;
    int x,y;
    while(M--) {
        in >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1);
    return 0;
}