|
|
back to boardWhy my program still WA?Please help me!Thank you! #include<iostream.h> #include<string.h> #define max 101 int n,q,note[max][max],tree[max][2],used[max]; long total; void init() { int a,b,s; memset(note,0,sizeof(note)); cin>>n>>q; while(cin>>a>>b>>s) {note[a][b]=note[b][a]=s;} } void make(int num) { int i,p; p=0; for(i=2;i<=n;i++) if((note[num][i])&&(!tree[i][0])) { tree[num][p]=i;make(i); if(p)return;else p++; } } void find(int num) { int a,b,i,j,k,sa,sb,ss,sum; a=tree[num][0];b=tree[num][1]; if(a)find(a);else for(i=0;i<=q;i++)note[a][i]=0; if(b)find(b);else for(i=0;i<=q;i++)note[b][i]=0; sa=note[num][a];sb=note[num][b]; for(i=0;i<=q;i++)note[num][i]=0; if(sa>sb)note[num][1]=sa;else note[num][1]=sb; for(i=1;i<=q;i++) { k=q-i;ss=sa+note[a][i]; if(note[num][i+1]<ss)note[num][i+1]=ss;ss+=sb; for(j=1;j<=k;j++) { sum=ss+note[b][j]; if(sum>note[num][i+j+2])note[num][i+j+2]=sum; } } } void work() { memset(tree,0,sizeof(tree)); memset(used,0,sizeof(used)); tree[1][0]=0; make(1); find(1); total=note[1][q]; } void out() { cout<<total<<endl; } void main() { init(); work(); out(); } Please give me some tests!!Thank you!! > #include<iostream.h> > #include<string.h> > > #define max 101 > > int n,q,note[max][max],tree[max][2],used[max]; > long total; > > void init() > { > int a,b,s; > memset(note,0,sizeof(note)); > cin>>n>>q; > while(cin>>a>>b>>s) > {note[a][b]=note[b][a]=s;} > } > > void make(int num) > { > int i,p; > p=0; > for(i=2;i<=n;i++) > if((note[num][i])&&(!tree[i][0])) > { > tree[num][p]=i;make(i); > if(p)return;else p++; > } > } > > void find(int num) > { > int a,b,i,j,k,sa,sb,ss,sum; > a=tree[num][0];b=tree[num][1]; > if(a)find(a);else for(i=0;i<=q;i++)note[a][i]=0; > if(b)find(b);else for(i=0;i<=q;i++)note[b][i]=0; > sa=note[num][a];sb=note[num][b]; > for(i=0;i<=q;i++)note[num][i]=0; > if(sa>sb)note[num][1]=sa;else note[num][1]=sb; > for(i=1;i<=q;i++) > { > k=q-i;ss=sa+note[a][i]; > if(note[num][i+1]<ss)note[num][i+1]=ss;ss+=sb; > for(j=1;j<=k;j++) > { > sum=ss+note[b][j]; > if(sum>note[num][i+j+2])note[num][i+j+2]=sum; > } > } > } > > void work() > { > memset(tree,0,sizeof(tree)); > memset(used,0,sizeof(used)); > tree[1][0]=0; > make(1); > find(1); > total=note[1][q]; > } > > void out() > { > cout<<total<<endl; > } > > void main() > { > init(); > work(); > out(); > } > |
|
|