Pagini recente » Cod sursa (job #1663228) | Cod sursa (job #2129772) | Cod sursa (job #1404584) | Cod sursa (job #1300639) | Cod sursa (job #2867150)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m, viz[50005], st[50005], top;
vector <int> h[50005];
void DFS(int k)
{
viz[k] = 1;
st[++top] = k;
for (int w : h[k])
if (viz[w] == 0) DFS(w);
}
void SortTop()
{
for (int i = 1; i <= n; i++)
if (viz[i] == 0) DFS(i);
}
void Afisare()
{
for (int i = 1; i <= top; i++)
fout << st[i] << " ";
fout << "\n";
fout.close();
}
int main()
{
int x, y;
fin >> n >> m;
while (m--)
{
fin >> x >> y;
h[x].push_back(y);
h[y].push_back(x);
}
SortTop();
Afisare();
fin.close();
return 0;
}