Tree Cutting
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 3849 |
|
Accepted: 2304 |
Description
After Farmer John realized, Bessie had installed a "tree-shaped" network among he N (1 <= N <=) Barns at An incredible cost, he sued Bessie to mitigate his losses.
Bessie, feeling vindictive, decided to sabotage Farmer John's network by cutting power to one of the barns (thereby Disrup Ting all the connections involving that barn). When Bessie does this, it breaks the network to smaller pieces, each of the which retains full connectivity within itself. In order to is as disruptive as possible, Bessie wants to make sure that each of the these pieces connects together no more th An half the barns on FJ.
Please help Bessie determine all of the barns that would is suitable to disconnect.
Input
* Line 1: A single integer, N. The barns is numbered 1..N.
* Lines 2..n:each line contains, integers x and y and represents a connection between barns X and Y.
Output
* Lines 1.: Contains a single integer, the number (from 1..N) of a barn whose removal splits the network into Pieces each has at most half the original number of barns. Output The barns in increasing numerical order. If there is no suitable barns, the output should is a single line containing the word "NONE".
Sample Input
101 22 33 44 56 77 88 99 103 8
Sample Output
38
Hint
INPUT DETAILS:
The set of connections in the input describes a "tree": it connects all the barns together and contains no cycles.
OUTPUT DETAILS:
If Barn 3 or Barn 8 is removed, then the remaining network would have one piece consisting of 5 barns and a pieces Contai Ning 2 Barns. If any other barn are removed then at least one of the remaining pieces have size at least 6 (which are more than half of the Original number of barns, 5).
Source
Usaco 2004 December Silver
POJ 2378:
Topic Meaning:
In a tree to remove some points, so that the tree can become some of the number of vertices containing not more than the original tree of some of the general tree, the need to delete the node, if there are multiple nodes, in ascending output ;
Problem Solving Ideas:
The tree is given a width-first traversal, if the number of nodes of a node is not more than N/2, and n minus the nodes of the tree with this node as the root node is less than or equal to n/2. The node is a node that can be deleted;
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <algorithm>6#include <vector>7 using namespacestd;8 Const intmaxn=10007;9 intDP[MAXN];Ten BOOLINPUT[MAXN]; Onevector<int>G[MAXN]; A intN; - voidInit () - { theMemset (DP,0,sizeof(DP)); -memset (Input,0,sizeof(input)); - for(intI=0; i<maxn;i++) - g[i].clear (); + } - voidBFsintPointintfather) + { Adp[point]=1; at BOOLflag=true;intnum=0; - for(intI=0; I<g[point].size (); i++) - { - intv=G[point][i]; - if(V==father)Continue; - BFS (v,point); in if(dp[v]>n/2) flag=false; -dp[point]+=Dp[v]; to } + if(flag&&n-dp[point]<=n/2) input[point]=true; - } the intMain () * { $ //freopen ("In.txt", "R", stdin);Panax Notoginseng intA,b,root; - while(~SCANF ("%d",&N)) { theInit (); root=-1; + for(intI=1; i<n;i++) A { thescanf"%d%d",&a,&b); + G[a].push_back (b); - G[b].push_back (a); $ } $BFs1,-1); - for(intI=1; i<=n;i++)if(Input[i]) printf ("%d\n", i); - } the return 0; -}
POJ 2378 tree-like DP