Pagini recente » Cod sursa (job #3132001) | Cod sursa (job #99660) | Cod sursa (job #1997408) | Cod sursa (job #1690625) | Cod sursa (job #2664960)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector<int> g[50005], sorted;
int n, m, v[50005];
void citire() {
fin >> n >> m;
while(m--) {
int x, y;
fin >> x >> y;
g[x].push_back(y);
}
}
void dfs(int x) {
v[x] = 1;
for(auto next: g[x])
if(!v[next])
dfs(next);
sorted.push_back(x);
}
void solve() {
for(int i = 1; i <= n; i++)
if(!v[i]) dfs(i);
}
void afis() {
for(int i = sorted.size()-1; i >= 0; i--)
fout << sorted[i] << ' ';
}
int main() {
citire();
solve();
afis();
}