Pagini recente » Cod sursa (job #2344382) | Cod sursa (job #2274609) | Cod sursa (job #2207650) | Cod sursa (job #831577) | Cod sursa (job #2568954)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
int n, m;
vector <int> h[50001];
int sol[50001], len;
bool viz[50001];
void Read()
{
int x, y;
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
fin >> x >> y;
h[x].push_back(y);
}
}
void DFS(int cNode)
{
viz[cNode] = true;
for(auto w : h[cNode])
if(viz[w] == false)
DFS(w);
sol[++len] = cNode;
}
void Print()
{
for(int i = len; i >= 1; i--)
fout << sol[i] << " ";
}
int main()
{
Read();
for(int i = 1; i <= n; i++)
if(viz[i] == false) DFS(i);
Print();
return 0;
}