Cod sursa(job #2254880)
| Utilizator | Data | 6 octombrie 2018 09:34:11 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
#include <vector>
constexpr const int NMAX = 5e4+5;
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector < int > g[NMAX];
short viz[NMAX];
int n, m;
void dfs(int nod){
if(viz[nod] < 1){
fout << nod << ' ';
viz[nod] = 1;
}
for(int i : g[nod])
if(!viz[i]){
viz[i] = -1;
dfs(i);
}
}
int main(){
fin >> n >> m;
for(int i = 0, x, y; i < m; i++){
fin >> x >> y;
g[x].push_back(y);
}
fin.close();
dfs(1);
fout.close();
return 0;
}
