Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位大神帮我看看啊,为什么WA啊,在下感激万分~#include<stdio.h> int catway[101][101]; int mouseway[101][101]; int pre[101]; int main(void) { int n,cat,mouse,i,j,x,y,flag; int cas; int changed; scanf("%d",&cas); while(cas--) { flag=0; changed=1; scanf("%d%d%d",&n,&cat,&mouse); for(i=1;i<=n;i++) for(j=1;j<=n;j++) catway[i][j]=mouseway[i][j]=0; catway[cat][cat]=1; mouseway[mouse][mouse]=1; while(scanf("%d%d",&x,&y)&&(x!=-1||y!=-1)) { catway[x][y]=1; } while(changed) { changed=0; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) if(catway[cat][i]&&catway[i][j]&&!catway[cat][j]) { catway[cat][j]=1; changed=1; } } } changed=1; while(scanf("%d%d",&x,&y)&&(x!=-1||y!=-1)) { mouseway[x][y]=1; pre[y]=x; } while(changed) { changed=0; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) if(mouseway[mouse][i]&&mouseway[i][j]&&!mouseway[mouse][j]) { changed=1; mouseway[mouse][j]=1; pre[j]=i; } } } for(i=1;i<=n;i++) { if(mouseway[mouse][i]&&catway[cat][i]) { printf("Y "); break; } } if(i==n+1) printf("N "); for(i=1;i<mouse;i++) if(mouseway[mouse][i]&&mouseway[i][mouse]) { for(j=i;j!=mouse;j=pre[j]) if(catway[cat][j]) break; if(j==mouse) { flag=1; break; } } if(flag==0) { for(i=mouse+1;i<=n;i++) if(mouseway[mouse][i]&&mouseway[i][mouse]) { for(j=i;j!=mouse;j=pre[j]) if(catway[cat][j]) break; if(j==mouse) { flag=1; break; } } } if(flag) printf("Y\n"); else printf("N\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator