ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1022. Genealogical Tree

I see,it's a bug!!!remove the newline character!!!!!
Posted by cool_wind_ 1 Nov 2002 20:26
#include<stdio.h>
void main()
{ int i,j,n,p,map[101][101],seq[101],in[101],head,tail;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      map[i][j]=0;

  for(i=1;i<=n;i++)
  { scanf("%d",&p);
    while(p)
    { map[i][p]=1;
      scanf("%d",&p);
    }
  }

  for(i=1;i<=n;i++)
  { in[i]=0;
    for(j=1;j<=n;j++)
      if(j!=i&&map[j][i]) in[i]++;
  }

  head=tail=0;
  do
  { for(i=1;i<=n;i++)
    { if(in[i]==0)
      { in[i]=-1;
    seq[tail++]=i;
      }
    }
    while(head<tail)
    { for(j=1;j<=n;j++)
    if(seq[head]!=j&&map[seq[head]][j]&&in[j]!=-1)
      in[j]--;
      head++;
    }
  }while(tail<n);

  for(i=0;i<n-1;i++)
    printf("%d ",seq[i]);
  printf("%d",seq[i]);



}
The standard output should contain in its ONLY line
Posted by Miguel Angel 2 Nov 2002 02:43
> #include<stdio.h>
> void main()
> { int i,j,n,p,map[101][101],seq[101],in[101],head,tail;
>   scanf("%d",&n);
>   for(i=1;i<=n;i++)
>     for(j=1;j<=n;j++)
>       map[i][j]=0;
>
>   for(i=1;i<=n;i++)
>   { scanf("%d",&p);
>     while(p)
>     { map[i][p]=1;
>       scanf("%d",&p);
>     }
>   }
>
>   for(i=1;i<=n;i++)
>   { in[i]=0;
>     for(j=1;j<=n;j++)
>       if(j!=i&&map[j][i]) in[i]++;
>   }
>
>   head=tail=0;
>   do
>   { for(i=1;i<=n;i++)
>     { if(in[i]==0)
>       { in[i]=-1;
>     seq[tail++]=i;
>       }
>     }
>     while(head<tail)
>     { for(j=1;j<=n;j++)
>     if(seq[head]!=j&&map[seq[head]][j]&&in[j]!=-1)
>       in[j]--;
>       head++;
>     }
>   }while(tail<n);
>
>   for(i=0;i<n-1;i++)
>     printf("%d ",seq[i]);
>   printf("%d",seq[i]);
>
>
>
> }
>
Yeah, it's a strange bug.
Posted by John Bill 2 Nov 2002 14:04