Pagini recente » Cod sursa (job #3255968) | Clasament pentru_clasele_5-8 | Cod sursa (job #1074039) | Cod sursa (job #935189) | Cod sursa (job #1329058)
#include <iostream>
#include <fstream>
#include <vector>
#define nmax 50001
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
vector<int> v[nmax];
vector<int> t;
int n, m;
bool seen[nmax];
void dfs(int x){
seen[x]= true;
for(int i=0; i<v[x].size(); i++)
if(!seen[v[x][i]]){
dfs(v[x][i]);
seen[v[x][i]]= true;
}
t.push_back(x);
}
int main(){
int x, y;
fin >> n >> m;
for(int i=1; i<=m; i++){
fin >> x >> y;
v[x].push_back(y);
}
for(int i=1; i<=n; i++)
if(!seen[i]) dfs(i);
for(int i=n-1; i>=0; i--) cout << t[i] << " ";
return 0;
}