Pagini recente » Cod sursa (job #2803691) | Cod sursa (job #2724151) | Cod sursa (job #2695228) | Cod sursa (job #2499062) | Cod sursa (job #2496916)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int N = 1e5 + 7;
bool used[N];
vector < int > adia[N];
vector < pair < int, int > > muchii;
int main()
{
int n, m, a, b;
fin >> n >> m;
while (m--) {
fin >> a >> b;
adia[a].push_back(muchii.size());
adia[b].push_back(muchii.size());
muchii.push_back({a, b});
}
vector < int > stk;
vector < int > ans;
stk.push_back(1);
while (stk.size()) {
int nod = stk.back();
while (adia[nod].size() && used[adia[nod].back()])
adia[nod].pop_back();
if (adia[nod].size()) {
used[adia[nod].back()] = 1;
stk.push_back(muchii[adia[nod].back()].first ^ muchii[adia[nod].back()].second ^ nod);
adia[nod].pop_back();
}
else {
ans.push_back(nod);
stk.pop_back();
}
}
for (int i = 0; i < ans.size() - 1; ++i)
fout << ans[i] << ' ';
return 0;
}