Pagini recente » Cod sursa (job #234622) | Cod sursa (job #2542977) | Cod sursa (job #1367283) | Cod sursa (job #1906505) | Cod sursa (job #265128)
Cod sursa(job #265128)
#include<fstream.h>
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int n,m,x,y,nr,i;
long a[5000][5000],viz[5000],postordine[5000];
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;
}