|
|
back to boardMy program got Wrong answer .Help me please! Posted by crazy 22 Apr 2002 11:20 I use BFS in the program #include<iostream.h> long x[2000],y[2000]; int queue[2000]; int parent[2000]; int path[2000]; int in[2000]; void main() { int n; int i,j,tot,current,step; int temp; long need; cin>>n; for(i=1;i<=n;i++){ in[i]=0; cin>>x[i]>>y[i]; } cin>>need>>x[0]>>y[0]; queue[0]=0; current=0; tot=1; while(current<tot){ if(x[queue[current]]==need||y[queue[current]]==need) break; for(i=1;i<=n;i++){ if(!in[i]){ if((x[i]==x[queue[current]])||(x[i]==y[queue [current]])||(y[i]==x[queue[current]])||(y[i]==y[queue[current]])){ queue[tot]=i; parent[i]=queue[current]; in[i]=1; tot++; } } } current++; } if(x[queue[current]]==need||y[queue[current]]==need){ step=0; temp=queue[current]; while(1){ if(temp==0) break; step++; path[step]=temp; temp=parent[temp]; } cout<<step<<endl; for(j=step;j>=1;j--){ cout<<path[j]<<endl; } }else{ cout<<"IMPOSSIBLE"<<endl; } } Re: My program got Wrong answer .Help me please! Posted by crazy 23 Apr 2002 15:30 when i change if((x[i]==x[queue[current]])||(x[i]==y[queue[current]]) ||(y[i]==x[queue[current]])||(y[i]==y[queue[current]])) {} into if((x[i]==x[queue[current]])||(x[i]==y[queue[current]]) {} i get ac. i did not read the problem carefully Anyone who got wrong answer should pay attention to it Re: My program got Wrong answer .Help me please! Thanks! But where it is mentioned in the problem statement??? Re: My program got Wrong answer .Help me please! Another THANKS from me, but really where is that mentioned in the problem's statement ? Re: My program got Wrong answer .Help me please! THANKS, man!
Well, there is a sentence in text: "The next K lines contain the number of the route of the corresponding bus and the number on the other side of its plate." But it is not explicitly said that first number in line is route number and that second number is from the other side of plate... Anyway, the point is that you can change your plate with driver i (which has plate x[i],y[i]) iff one of the numbers on your plate is x[i] (not x[i] OR y[i]). |
|
|