Pagini recente » Cod sursa (job #75550) | Cod sursa (job #2063230) | Cod sursa (job #1522480) | Cod sursa (job #603499) | Cod sursa (job #2195698)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
int x, y, n, m, st[50100], vf;
vector <int> v[50100];
bitset <50100> viz;
void dfs(int from){
viz[from] = 1;
for(auto to : v[from])
if(!viz[to])
dfs(to);
st[++vf] = from;
}
int main(){
in >> n >> m;
while(m--){
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;
}