3391: [Usaco2004 dec]tree Cutting Network damage

Source: Internet
Author: User

3391: [Usaco2004 dec]tree cutting Network damage time limit:1 Sec Memory limit:128 MB
submit:76 solved:59
[Submit] [Status] [Discuss] Description John, realizing that Bessie's construction network had cost him a huge amount of money, fired her. Bessie was furious and intended to retaliate.    She intends to destroy the newly built network of John. John's network is tree-shaped, connected to the N (1≤n≤10000) barn. She intends to cut off the power of one of the barns, leaving all the cables connected to the barn completely interrupted. After that, there will be several sub-networks. To ensure that the damage is large enough, each subnet should not be more than half of the number of cattle sheds, which is worth destroying the barn?    Input line 1th: an integer n. 2nd to n+1: Enter two integers per line representing the two endpoints of a cable. Output outputs all the damage-worthy barns in order from small to large. If no one is worth destroying, the output is "NONE". Sample Input10
1 2
2 3
3 4
4 5
6 7
7 8
8 9
9 10
3 8Sample Output3
8

If the Barn 3 or bullpen 8 is destroyed, the remaining three subnet nodes will be 5,2,2, with no more than 5.
Source information
HINT Source

Silver

Problem: A tree of water, the key is how to quickly find the size of the sub-tree around the point, in fact, only need DFS preprocessing to a certain point (such as point 1) as the root of the tree each subtree size, and for a certain point, the size of each subtree is in the case of a root tree of its individual subtree size, There is another subtree size that is n-size[x] (size[x) is labeled as the size of the subtree with the root tree in the case of the root, and then simple to determine, the complexity O (N)
1/**************************************************************2Problem:33913 User:hansbug4 language:pascal5 result:accepted6Time: -Ms7Memory:1716KB8****************************************************************/9  Ten type OnePoint=^node; ANode=Record - G:longint; - Next:point; the     End; - var - I,j,k,l,m,n:longint; -A:Array[0..100000] ofPoint ; +B:Array[0..100000] ofLongint; -C:Array[0..100000] ofLongint; + 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;i:longint; in           begin -p:=a[x];b[x]:=1; i:=1; to                 whileP<>Nil  Do +                      begin -                           ifP^.g<>y Then the                              begin * DFS (X,P^.G); $                                   ifB[p^.g]> (nDiv 2) Theni:=0;Panax Notoginseng Inc (B[X],B[P^.G]); -   the                              End; +p:=P^.next; A                      End; the                if((N-b[x]) <= (nDiv 2)) and(i=1) Then +                   begin -Inc (c[0]); $c[c[0]]:=x; $                   End; -           End; - proceduresort (l,r:longint); the           varI,j,x,y:longint; -           beginWuyii:=l;j:=r;x:=c[(L+r)Div 2]; the                Repeat -                       whileC[i]<x DoInc (i); Wu                       whileC[j]>x DoDec (j); -                      ifI<=j Then About                         begin $y:=c[i];c[i]:=c[j];c[j]:=y; - Inc (I);d EC (j); -                         End; -                untilI>J; A                ifI<r Thensort (i,r); +                ifL<j Thensort (l,j); the           End; - begin $READLN (n); c[0]:=0; the       fori:=1  toN Doa[i]:=Nil; the       fori:=1  toN-1  Do the          begin the readln (j,k); - Add (j,k); add (k,j); in          End; theDfs0,1); Sort (1, c[0]); the       fori:=1  toc[0] DoWriteln (C[i]); About Readln; the End.

3391: [Usaco2004 dec]tree Cutting Network damage

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.