Cod sursa(job #2195701)
| Utilizator | Data | 17 aprilie 2018 10:20:34 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
int x, y, n, m, st[50100], vf;
vector <int> v[50100];
bitset <50100> viz;
void dfs(int from){
viz[from] = 1;
for(auto to : v[from])
if(!viz[to])
dfs(to);
st[++vf] = from;
}
int main(){
in >> n >> m;
while(m--){
in >> x >> y;
v[x].push_back(y);
}
for(int i = 1; i <= n; i++)
if(!viz[i])
dfs(i);
for(; vf; vf--)
out << st[vf] << ' ';
return 0;
}
