CF1187E Tree Painting【换根dp】

Topic Portal

#### question is intended
a $ N $ tree nodes, all nodes are initially white, can select any one of the first time it is painted black. Subsequently, only the black and white node connected to the node of the original painted black (painted black point is regarded as omitted, not connected to other nodes). Each time the number of blocks Unicom coating coated the white fraction node is located in a white node. It should $ N $ nodes are painted black, seeking maximum score obtainable.
(Translation + artificial hand to play qwq, if any error please let me know)

Analysis of ###
~ does not have much idea of the problem first fucks ~~

Then we find ourselves at the beginning of this tree just after one of the nodes painted black coating on the tree uniquely determined. After coating the tree will be scattered into many little tree, this tree if we mentioned it, the point that most start painting is regarded as the root, the tree becomes a sub-tree roots. And it can only painted white with black node connected to the original node, which is the only son who painted the original roots. And the order of root son was painted does not affect the answer (they have become Unicom block is not connected, which is first coated with a block Unicom will not affect the answer), so the answer is determined.

---

In other words, we start from the root coating, different choices of roots, the answer is different. Then we will all nodes as a root, then the simulation time, whichever is greater, on it.

---
But this complexity is too high.
Let us analyze this simulation process.

! [] (https://img-blog.csdnimg.cn/20190701211235346.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NRQlpMWVRpbmE=,size_16,color_FFFFFF,t_70)
we observe this node: 9
it is the case of the calculation are: 1 when deleting, deleting 6, 7 deleting, deleting 9:00
that is, it's every father or their own time were omitted, it must be accounted for in the answers
so it the answer is that the number of contributions to its father + 1 = depth

The contribution of each node of the answer to both its depth
answer is that all nodes of depth and

---
again consider changing the root of the problem
is this picture
! [] (Https://img-blog.csdnimg.cn/20190701211557574.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NRQlpMWVRpbmE=, size_16, color_FFFFFF, t_70)
when a change from the root to 6, 8, 9 (i.e. subtrees 6) have a depth of -1, and the depth of the other nodes are +1

! [] (https://img-blog.csdnimg.cn/20190701211737103.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NRQlpMWVRpbmE=,size_16,color_FFFFFF,t_70)
so the father from the root to change son, the answer will be less $ size [son] $ and will be more than $ (n-size [son] ) $, so we re-iterate what the tree, the roots change from father to son to go there, and then calculate the answer, take maximum. (** Note ** To back)

Guess you like

Origin www.cnblogs.com/lyttt/p/11801293.html