Pagini recente » Cod sursa (job #1940154) | Cod sursa (job #89060) | Cod sursa (job #2259586) | Cod sursa (job #482712) | Cod sursa (job #2152307)
#include <bits/stdc++.h>
#define NMax 50006
using namespace std;ifstream fin("sortaret.in");ofstream fout("sortaret.out");vector <int> L[NMax];int n, m, K;int drum[NMax];bool viz[NMax];inline void Citire(){int i, x, y;fin >> n >> m;for(i = 1; i <= m; i++){fin >> x >> y;L[x].push_back(y);}}void DFS(int nod){int i, j;viz[nod] = 1;for(j = 0; j < L[nod].size(); j++){i = L[nod][j];if(!viz[i])DFS(i);}drum[++K] = nod;}inline void SortareTop(){int i;for(i = 1; i <= n; i++)if(!viz[i])DFS(i);}inline void Afisare(){int i;for(i = n; i >= 1; i--)fout << drum[i] << " ";fout << "\n";}int main(){Citire();SortareTop();Afisare(); return 0;}