Pagini recente » Cod sursa (job #2743845) | Cod sursa (job #972613) | Cod sursa (job #1657976) | Cod sursa (job #1143344) | Cod sursa (job #1306479)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define nmax 100005
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
int n, m ,i, x, y;
vector <int> v[nmax];
vector <int> topp;
bool seen[nmax];
void dfs(int x){
seen[x] = true;
for(int i=0; i<v[x].size(); i++)
if(!seen[v[x][i]]){
seen[v[x][i]] = true;
dfs(v[x][i]);
}
topp.push_back(x);
}
int main(){
fin >> n >> m;
for(i=1; i<=m; i++){
fin >> x >> y;
v[x].push_back(y);
}
for(i=1; i<=n; i++) if(!seen[i]) dfs(i);
for(i=n-1; i>=0; i--) fout << topp[i] << " ";
return 0;
}