Pagini recente » Cod sursa (job #1274482) | Istoria paginii runda/oni_2015_zi1/clasament | Cod sursa (job #2771508) | Cod sursa (job #3127879) | Cod sursa (job #2738614)
#include <bits/stdc++.h>
#define Nmax 50005
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int N, M;
bool in[Nmax], vis[Nmax];
vector<int> G[Nmax], nodes;
void DFS(int node) {
vis[node] = 1;
for (auto it: G[node])
if (!vis[it]) DFS(it);
nodes.push_back(node);
}
int main()
{
fin >> N >> M;
while (M--) {
int x, y;
fin >> x >> y;
G[x].push_back(y);
in[y] = 1;
}
for (int i = 1; i <= N; ++i)
if (!in[i]) DFS(i);
reverse(nodes.begin(), nodes.end());
for (auto it: nodes)
fout << it << " ";
return 0;
}