Pagini recente » Cod sursa (job #906416) | Cod sursa (job #501572) | Cod sursa (job #2559123) | Cod sursa (job #372405) | Cod sursa (job #2424202)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int postOrdine[50005], nr;
vector<int> Muchii[50005];
bool viz[50005];
void DFS(int nod){
viz[nod] = 1;
for(int i = 0; i < Muchii[nod].size(); ++i)
if(!viz[Muchii[nod][i]])
DFS(Muchii[nod][i]);
postOrdine[++nr] = nod;
}
int main()
{
int n, m;
fin >> n >> m;
for(int i = 1; i <= m; ++i){
int x, y;
fin >> x >> y;
Muchii[x].push_back(y);
}
for(int i = 1; i <= n; ++i)
if(!viz[i])
DFS(i);
for(int i = n; i >= 1; --i)
fout << postOrdine[i] << ' ';
fout << '\n';
return 0;
}