Pagini recente » Cod sursa (job #2389012) | Cod sursa (job #2827882) | Cod sursa (job #735187) | Cod sursa (job #2335442) | Cod sursa (job #2207563)
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > PII;
int n, m, inD[50010];
vector < int > V[50100];
stack < int > R;
bitset < 50010 > B;
void dfs(int x){
B[x] = 1;
for (auto it : V[x]){
if (B[it]) continue;
dfs(it);
}
R.push(x);
}
int main(){
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
cin >> n >> m;
for (int i = 1, x, y; i <= m; i++){
cin >> x >> y;
V[x].push_back(y);
inD[y]++;
}
int root = 0;
for (int i = 1; i <= n; i++)
if (inD[i] == 0) root = i;
dfs(root);
while (R.size()){
cout << R.top() << " ";
R.pop();
}
return 0;
}