### 10305 - Ordering Tasks

Posted:

**Mon Mar 17, 2003 8:45 am**first please check,,
if any one helps me i will be greatfull.

pleases ...

thanks.....

[/b]

Code: Select all

```
cut it off please don't mind..
it's a sol after some reply...
thanks to tomal bhai...
```

**this is a simple code of topological sorting,,**

but i get wa for several times..

i can't understand why?

then i tried a very easy algirithm..

just compute the in degree of graph nodes but again wa..

am i missing something??

please please help...

i have no way left..

the second code... is pasted here....

please don't mind, i pasted it after at least 10 trials..and getting wa....

but i get wa for several times..

i can't understand why?

then i tried a very easy algirithm..

just compute the in degree of graph nodes but again wa..

am i missing something??

please please help...

i have no way left..

the second code... is pasted here....

please don't mind, i pasted it after at least 10 trials..and getting wa....

Code: Select all

```
#include<stdio.h>
#define N 100
main()
{
freopen("in.txt","r",stdin);
int m,n,b[N],out[N],i,j,c,d,h,e[N],f[N],high,l,k,r[N],pr;
while(1)
{
scanf("%d%d",&n,&m);
pr=0;
if(m==0 && n==0) break;
for(i=0;i<n;i++) b[i]=out[i]=0,r[i]=i;
for(i=0;i<m;i++)
{
scanf("%d%d",&c,&d);
b[c-1]++;out[d-1]++;
}
for(i=0;i<n-1;i++)
{
h=i;
for(j=i+1;j<n;j++)
if(b[j]>b[h]) h=j;
c=b[h];
d=out[h];
b[h]=b[i];
out[h]=out[i];
out[i]=d;
b[i]=c;
c=r[i];
r[i]=r[h];
r[h]=c;
}
high=0;
for(i=0;i<n;i++) if(b[i]>high) high=b[i];
for(;high>=0;high--)
{
l=0;
for(j=0;j<n;j++) if(b[j]==high) e[l]=j,f[l++]=out[j];
for(j=0;j<l-1;j++)
{
h=j;
for(k=j+1;k<l;k++)
if(out[e[k]]<out[e[h]]) h=k;
k=e[j];
e[j]=e[h];
e[h]=k;
}
for(i=0;i<l;i++)
{
if(pr) printf(" ");
else pr=1;
printf("%d",e[i]+1);
}
}
printf("\n");
}
return 0;
}
```

pleases ...

thanks.....

[/b]