Cod sursa(job #152226)
| Utilizator | Data | 9 martie 2008 11:15:35 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <stdio.h>
#define maxn 50010
int n,m;
int a[maxn], p[maxn];
int main()
{
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
scanf("%d %d ",&n,&m);
int i,x,y;
for (i=1;i<=n;i++) a[i] = p[i] = i;
for (i=1;i<=m;i++)
{
scanf("%d %d ",&x,&y);
if (p[x] > p[y])
{
int aux;
aux = a[x], a[x] = a[y], a[y] = aux;
p[a[x]] = x;
p[a[y]] = y;
}
}
for (i=1;i<=n;i++) printf("%d ",a[i]);
return 0;
}
