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

Common Board

why i got crash (access vio..) in this code for problem 1008,pls help me
Posted by TheBlaNK 7 Feb 2002 18:57
why i got crash (access vio..) in this code for problem 1008,pls help me

#include <stdio.h>
struct node
 {
   long x,y;
 };
struct node que[155];
long sf=-1,sl=-1;
long graph[11][11],know[11][11];
void bfs(long i,long j)
{
  if(i>=0&&i<=9&&(j+1)>=0&&(j+1)<=9&&graph[i][j+1]&&!know[i]
[j+1])
    { sl++; que[sl].x=i; que[sl].y=j+1; know[i][j+1]=1; printf("R"); }
  if((i-1)>=0&&(i-1)<=9&&j>=0&&j<=9&&graph[i-1][j]&&!know[i-1][j])
    { sl++; que[sl].x=i-1; que[sl].y=j; know[i-1][j]=1; printf("B"); }
  if(i>=0&&i<=9&&(j-1)>=0&&(j-1)<=9&&graph[i][j-1]&&!know[i][j-1])
    { sl++; que[sl].x=i; que[sl].y=j-1; know[i][j-1]=1; printf("L"); }
  if((i+1)>=0&&(i+1)<=9&&j>=0&&j<=9&&graph[i+1][j]&&!know[i+1]
[j])
    { sl++; que[sl].x=i+1; que[sl].y=j; know[i+1][j]=1; printf("T"); }
  while(sf<sl)
    {
       printf(",\n");
       sf++;
       bfs(que[sf].x,que[sf].y);
    }
}

int main()
{
 long n,tmp1,tmp2;
 long bi,bj,i;
 scanf("%ld",&n);
 scanf("%ld %ld",&bj,&bi);
  graph[bi-1][bj-1]=1;
  for(i=1;i<n;i++)
   {
    scanf("%ld %ld",&tmp2,&tmp1);
     graph[tmp1-1][tmp2-1]=1;
   }
 printf("%ld %ld\n",bj,bi);
 bi--; bj--;
 know[bi][bj]=1;
 bfs(bi,bj);
 printf(".");
 return 0;
}