1907: Tree Path Overlay

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.