Title effect: given a tree. After removing a point, the tree will become a chunk of some Chinese unicom. The point is then removed by seeking the maximum number of minimum formed blocks.
Thinking: Tree dp thinking. Determined by deep search for the root node of each subtree size. After that the node is then removed, and there is the remainder. Find the maximum number of these blocks. is to remove this point when the ANS. Then update the total ans.
The problem is actually the center of the tree.
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 20010using namespace Std;int cases;int points;int head[max],total;int next[max << 1],aim[max << 1];int P_ans, ans;inline void Initialize (), inline void Add (int x,int y), int DFS (int x,int last), int main () {for (CIN >> cases;cases; --cases) {scanf ("%d", &points); Initialize (); for (int x,y,i = 1;i < points; ++i) {scanf ("%d%d", &x,&y); Add (x, y), add (y,x);} DFS (1,0);p rintf ("%d%d\n", P_ans,ans);} return 0;} inline void Initialize () {ans = 0x7f7f7f7f,total = 0;memset (head,0,sizeof (Head));} inline void Add (int x,int y) {next[++total] = head[x];aim[total] = y;head[x] = total;} int DFS (int x,int last) {int max_size = 0,size = 1;for (int i = Head[x];i;i = Next[i]) {if (aim[i] = = last) Continue;int Temp = DFS (aim[i],x); max_size = max (max_size,temp); size + = temp;} Max_size = max (max_size,points-size); if (max_size < ans) ans = Max_size,p_ans = X;return size;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
POJ 1655 balancing Act Focus Tree