Pagini recente » Cod sursa (job #1977913) | Cod sursa (job #3250860) | Cod sursa (job #1227042) | Cod sursa (job #2597721) | Cod sursa (job #1898780)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
struct nod
{
int info;
nod *urm;
}**v;
vector<int>postordine;
int *viz,n,m,nr;
void add(int x,int y)
{
nod *p=new nod;
p->info=y;
p->urm=v[x];
v[x]=p;
}
void DFS(int x)
{
viz[x]=1;
for(nod *e=v[x];e;e=e->urm)
if(!viz[e->info])
DFS(e->info);
postordine.push_back(x);
}
int main()
{
fin>>n>>m;
viz=new int[n+1];
v=new nod *[n+1];
for(int i=1; i<=m; i++)
{
int b,c;
fin>>b>>c;
add(c,b);
}
for(int i=1;i<=n;i++)
if(!viz[i])
DFS(i);
for(int i=0;i<postordine.size();i++)
fout<<postordine[i]<<" ";
return 0;
}