Pagini recente » Cod sursa (job #308066) | Cod sursa (job #212938) | Cod sursa (job #1761848) | Cod sursa (job #2842003) | Cod sursa (job #2014256)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int n_max = 50005;
int n, m, top, ans[n_max];
vector <int> L[n_max];
bool used[n_max];
inline void Read() {
fin >> n >> m;
int x, y, i;
for (i = 1; i <= m; i++) {
fin >> x >> y;
L[x].push_back(y);
}
fin.close();
}
void Sorting(int nod) {
used[nod] = 1;
for (auto i : L[nod])
if (!used[i])
Sorting(i);
ans[++top] = nod;
}
int main() {
Read();
for (int i = 1; i <= n; i++)
if (!used[i]) Sorting(i);
do {
fout << ans[top] << " ";
} while (--top);
fout.close();
return 0;
}