Pagini recente » Cod sursa (job #3279497) | Cod sursa (job #1362708) | Cod sursa (job #641455) | Cod sursa (job #3245118) | Cod sursa (job #265125)
Cod sursa(job #265125)
#include<fstream.h>
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int n,m,x,y,nr,i;
long a[50000][50000],viz[50000],postordine[50000];
void dfs(int x)
{
int i;
viz[x]=1;
for(i=1;i<=a[x][0];i++)
if(!viz[a[x][i]])
dfs(a[x][i]);
postordine[++nr]=x;
}
int main()
{
f>>n>>m;
for(i=1;i<=m;i++)
{
f>>x>>y;
a[x][0]++;
a[x][a[x][0]]=y;
}
for(i=1;i<=n;i++)
if(!viz[i])
dfs(i);
for(i=n;i>0;i--)
g<<x<<" ";
return 0;
}