| 
 | 
вернуться в форумDP solution, but why WA? Can anyone tell me what is wrong? I tested it a lot and everything seems correct, I even ignore branches with 0 apples... It passed all tests on this webboard,yet it's still WA! I used DP to try to solve it, here is the code:   var a:array[1..100,1..100] of longint;     m,g,min:array[0..100] of longint;     v:array[1..100] of 0..1;     n,i,j,k,l,q:longint; procedure df(x,t:integer); var i:integer; begin   v[x]:=1;   g[x]:=0; m[x]:=0;   for i:=1 to n do       if (a[x,i]<>0) and (v[i]=0) then begin          df(i,x); g[x]:=g[x]+g[i]; m[x]:=m[x]+m[i];          end;   if t<>0 then begin      g[x]:=g[x]+1;      m[x]:=m[x]+a[t,x];      end; end; begin   fillchar(a,sizeof(a),0);   fillchar(v,sizeof(v),0);   {assign(input,'input.txt'); reset(input);}   readln(n,q);   for k:=1 to n-1 do begin       readln(i,j,l);       a[i,j]:=l; a[j,i]:=l;       if l=0 then dec(q);       end;   df(1,0);   l:=m[1];   for i:=1 to n do min[i]:=maxint;   min[0]:=0;   for i:=1 to n-1 do       for j:=i+1 to n do           if g[i]>g[j] then begin              k:=g[i]; g[i]:=g[j]; g[j]:=k;              k:=m[i]; m[i]:=m[j]; m[j]:=k;              end;   for i:=1 to n do       for j:=n-g[i]-1 downto 0 do           if min[j]+m[i]<min[j+g[i]] then min[j+g[i]]:=min[j]+m[i];   writeln(l-min[q]); end.   My e-mail is vlad_io1@yahoo.com, if you don't understand the code or know what's wrong just mail me pls. Thanks! I`ve same status.... but I know our WA is about branches with zero apples(-) Re: I`ve same status.... but I know our WA is about branches with zero apples(-) > Impossible. If you made a good DP, you shouldn't havw any trouble solving it correctly.  |  
  | 
|