Pagini recente » Cod sursa (job #140986) | Cod sursa (job #2557376) | Cod sursa (job #1851029) | Cod sursa (job #2905024) | Cod sursa (job #1880221)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int N = 50001;
vector<int> v[N];
int n, m, stop[N], nr;
bool viz[N];
void citire(){
ifstream r("sortaret.in");
r >> n >> m;
int i, x, y;
for(i=0; i<m; i++){
r >> x >> y;
v[x].push_back(y);
}
r.close();
}
void dfs(int x){
int i, y;
viz[x] = true;
for(i=0; i<v[x].size(); i++){
y = v[x][i];
if(!viz[y])
dfs(y);
}
stop[++nr] = x;
}
int main()
{
ofstream w("sortaret.out");
int i;
citire();
for(i=1; i<=n; i++)
if(!viz[i])
dfs(i);
for(i=nr; i>=1; i--)
w<<stop[i]<<" ";
return 0;
}