Cod sursa(job #947000)
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iterator>
#include <algorithm>
using namespace std;
const int NMAX = 50011;
bool was[NMAX];
vector<int> dfs;
vector<int> G[NMAX];
inline void DFS(int x)
{
was[x] = true;
for(auto& y : G[x])
{
if(!was[y])
{
DFS(y);
}
}
dfs.push_back(x);
}
int main()
{
int N, M, x, y;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
for(in >> N >> M; M; --M)
{
in >> x >> y;
G[x].push_back(y);
}
dfs.reserve(N);
for(x = 1; x <= N; ++x)
if(!was[x])
DFS(x);
copy(dfs.rbegin(), dfs.rend(), ostream_iterator<int>(out, " "));
out << '\n';
return EXIT_SUCCESS;
}