Pagini recente » Cod sursa (job #700594) | Cod sursa (job #632773) | Cod sursa (job #607287) | Cod sursa (job #2660822) | Cod sursa (job #3214651)
///tarjan intai
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream cin ("sortaret.in");
ofstream cout ("sortaret.out");
const int N = 5e4;
bool viz[N + 1];
vector <int> g[N + 1], topo;
int n, m, x, y;
void dfs (int node)
{
viz[node] = 1;
for (auto it : g[node])
if (!viz[it])
dfs (it);
topo.push_back(node);
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; ++i)
{
cin >> x >> y;
g[x].push_back(y);
}
for (int i = 1; i <= n; ++i)
if (!viz[i])
dfs(i);
reverse (topo.begin(), topo.end());
for (auto it : topo)
cout << it << ' ';
return 0;
}