Pagini recente » Cod sursa (job #578721) | Cod sursa (job #886144) | Cod sursa (job #1390561) | Cod sursa (job #2703105) | Cod sursa (job #2551467)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
int n, m;
vector<int> G[100001], R;
vector<pair<int, int>> M;
bool V[500001];
void Dfs(int x)
{
for (int i : G[x])
{
if (!V[i])
{
V[i] = true;
Dfs(M[i].first == x ? M[i].second : M[i].first);
}
}
R.push_back(x);
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= m; ++i)
{
int x, y;
fin >> x >> y;
M.emplace_back(x, y);
G[x].push_back(M.size() - 1);
G[y].push_back(M.size() - 1);
}
Dfs(1);
for (int i = 1; i < R.size(); ++i)
fout << R[i] << " ";
return 0;
}