Cod sursa(job #3268066)

Utilizator solicasolica solica solica Data 13 ianuarie 2025 16:43:14
Problema Ciclu Eulerian Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.42 kb
/*
  ____   ___  _     ___ ____    _
 / ___| / _ \| |   |_ _/ ___|  / \
 \___ \| | | | |    | | |     / _ \
  ___) | |_| | |___ | | |___ / ___ \
 |____/ \___/|_____|___\____/_/   \_\

*/
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define int long long int
#define pii pair<int,int>

const int NMAX = 2e5+9;

const int MOD = 1e9+7;

int binpow(int n, int k)
{
    if (k==0)
    {
        return 1;
    }
    int x=binpow(n,k/2)%MOD;
    if (k%2==0)
    {
        return x*x%MOD;
    }
    else
    {
        return x*x%MOD*n%MOD;
    }
}

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

#define cin fin
#define cout fout

map<pair<int,int>,int>mep;

int n,i,j,m,a,b;

vector<int>g[NMAX];

vector<int>stiva;

void dfs (int node)
{
    while (!g[node].empty())
    {
        int it = g[node].back();
        g[node].pop_back();
        if (mep[{node,it}])
        {
            mep[{node,it}]--,mep[{it,node}]--;
            dfs(it);
        }
    }
    cout<<node<<' ';
}

void run_case ()
{
    cin>>n>>m;
    for (i=1; i<=m; i++)
    {
        cin>>a>>b;
        g[a].pb (b),g[b].pb (a);
        mep[{a,b}]++;
        mep[{b,a}]++;
    }
    dfs(1);
}

signed main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL),cout.tie ();
    int teste;
    teste=1;
    while (teste--)
    {
        run_case();
    }
}