Cod sursa(job #2922383)
| Utilizator | Data | 8 septembrie 2022 09:45:48 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m, top[50005], k;
vector <int> a[50005];
void Dfs(int x)
{
for (auto w: a[x])
Dfs(w);
top[++k] = x;
}
int main()
{
int i, j;
fin >> n >> m;
while (m--)
{
fin >> i >> j;
a[i].push_back(j);
}
Dfs(1);
for (i = n; i >= 1; i--)
fout << top[i] << " ";
return 0;
}
