Cod sursa(job #151519)
| Utilizator | Data | 8 martie 2008 11:58:03 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <stdio.h>
#define vv 50005
using namespace std;
int n,m,s,a[vv][vv],v[vv];
void citire()
{
freopen("sortaret.in","r",stdin);
scanf("%d%d%d", &n, &m, &s);
int x,y;
for (int i=0; i<n; i++)
{
scanf("%d%d", &x, &y);
a[x][y]=1;
}
fclose(stdin);
}
void topo(int w)
{
v[w]=1;
for (int i=1; i<=n; i++)
if (a[w][i]>0 && v[i]==0)
topo(i);
printf("%d ", w);
}
int main()
{
citire();
freopen("sortaret.out","w",stdout);
topo(s);
fclose(stdout);
return 0;
}