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 |
帮别人改程序真麻烦...不过AC了,虽然不是自己写的...In Reply To:为什么会RE?? Posted by:butter at 2007-04-04 20:20:15 RUNTIME ERROR 的原因是有的结点只有父或母结点... 另外<=3改为<3 MAXN 为101就OK了... 居然这样改了之后排第一BEST SOLUTION,假! #include <cstdio> #define MAXN 1101 struct node { int f,m; int sex; int deep1,deep2; }vert[MAXN]; int temp[MAXN]; void find1(int i) { if(vert[i].f==i&&vert[i].m==i) return; if(vert[i].f!=i){vert[vert[i].f].deep1=vert[i].deep1+1;find1(vert[i].f);} if(vert[i].m!=i){vert[vert[i].m].deep1=vert[i].deep1+1;find1(vert[i].m);} } void find2(int i) { if(vert[i].f==i&&vert[i].m==i) return; if(vert[i].f!=i){vert[vert[i].f].deep2=vert[i].deep2+1;find2(vert[i].f);} if(vert[i].m!=i){vert[vert[i].m].deep2=vert[i].deep2+1;find2(vert[i].m);} } int main() { int p1,p2,i,j,v,t; scanf("%d%d",&p1,&p2); for(i=1;i<=MAXN-1;i++) { vert[i].f=vert[i].m=i; vert[i].deep1=vert[i].deep2=10; vert[i].sex=0; } while(scanf("%d",&v)!=EOF) { temp[0]=0; while(1) { scanf("%d",&temp[++temp[0]]); if(temp[temp[0]]<=0) { vert[v].sex=temp[temp[0]]; break; } } if(vert[v].sex==0) for(i=1;i<temp[0];i++) vert[temp[i]].f=v; else for(i=1;i<temp[0];i++) vert[temp[i]].m=v; } if(vert[p1].sex==vert[p2].sex) { printf("same\n"); return 0; } else { vert[p1].deep1=0; find1(p1); vert[p2].deep2=0; find2(p2); for(i=1;i<MAXN;i++) if((vert[i].deep1<=3)&&(vert[i].deep2<=3)) { printf("close\n"); goto label; } printf("marriage\n"); } label: return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator