1907: Tree Path overlay time limit:5 Sec Memory limit:259 MB
submit:506 solved:219
[Submit] [Status] [Discuss] Descriptioninputoutputsample Input1
7
1 2
2 3
2 4
4 6
5 6
6 7Sample Output3HINT
Source
Play with the Tree by Amber
Problem: Greedy question, the DA, direct DFS once again just fine
1/**************************************************************2Problem:19073 User:hansbug4 language:pascal5 result:accepted6Time:392Ms7Memory:3480KB8****************************************************************/9 Ten type OnePoint=^node; ANode=Record - G:longint; - Next:point; the End; - var - I,j,k,l,m,n,tot,t:longint; -A:Array[0..100000] ofPoint ; +B:Array[0..100000] ofLongint; -C:Array[0..100000] ofBoolean; + procedureAdd (x,y:longint); A varP:point; at begin -New (p);p ^.g:=y;p^.next:=a[x];a[x]:=p; - End; - procedureDFS (y,x:longint); - varP:point;tot:longint; - begin inb[x]:=1; tot:=0;p: =A[x]; - whileP<>Nil Do to begin + ifP^.g<>y Then - begin the DFS (X,P^.G); * Inc (B[X],B[P^.G]); $ if not(C[P^.G]) ThenInc (TOT);Panax Notoginseng End; -p:=P^.next; the End; + iftot>=2 Then A begin theDec (b[x),2); +c[x]:=true; - End $ Else iftot=1 ThenDec (b[x]); $ End; - begin - readln (t); the whileT>0 Do - beginWuyi READLN (n); theFillchar (b,sizeof (b),0); - Fillchar (C,sizeof (c), false); Wu fori:=1 toN Doa[i]:=Nil; - fori:=1 toN-1 Do About begin $ readln (j,k); - Add (j,k); add (k,j); - End; -Dfs0,1);d EC (t); AWriteln (b[1]); + End; the End.
1907: Tree Path Overlay