Pagini recente » Cod sursa (job #2521739) | Cod sursa (job #2005442) | Cod sursa (job #1337166) | Cod sursa (job #2174244) | Cod sursa (job #2425286)
#include <bits/stdc++.h>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
int n, m, x, y, viz[100100], st[100100], vf;
vector<int> v[100100];
void dfs(int x) {
viz[x] = 1;
for (auto y : v[x])
if (!viz[y])
dfs(y);
st[++vf] = x;
}
int main() {
in >> n >> m;
for (int i = 1; i <= m; i++) {
in >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
for (int i = 1; i <= n; i++)
if (!viz[i])
dfs(i);
for (; vf; vf--)
out << st[vf] << ' ';
return 0;
}