Pagini recente » Cod sursa (job #1741908) | Cod sursa (job #598929) | Cod sursa (job #1806032) | Cod sursa (job #364206) | Cod sursa (job #2441097)
#include <bits/stdc++.h>
#define N 50005
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
int n, m, a, b;
bool gasit[N];
vector <int> L[N];
list <int> ans;
void DFS(int nod)
{
gasit[nod] = 1;
for (auto &next_nod : L[nod])
{
if (!gasit[next_nod])
DFS(next_nod);
}
ans.push_front(nod);
}
int main()
{
fin >> n >> m;
while (m--)
{
fin >> a >> b;
L[a].push_back(b);
}
for (int i = 1; i <= n; i++)
{
if (!gasit[i])
DFS(i);
}
for (auto &it : ans)
fout << it << " ";
return 0;
}