CF1842F.Tenzing and Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tenzing has an undirected tree of nn vertices.

Define the value of a tree with black and white vertices in the following way. The value of an edge is the absolute difference between the number of black nodes in the two components of the tree after deleting the edge. The value of the tree is the sum of values over all edges.

For all kk such that 0kn0 \leq k \leq n , Tenzing wants to know the maximum value of the tree when kk vertices are painted black and nkn-k vertices are painted white.

输入格式

The first line of the input contains a single integer nn ( 1n50001\leq n\leq 5000 ) — the number of vertices.

The following n1n-1 lines of the input contains 22 integers uiu_i and viv_i ( 1ui,vin,uivi1 \leq u_i, v_i \leq n, u_i \neq v_i ) — indicating an edge between vertices uiu_i and viv_i . It is guaranteed that the given edges form a tree.

输出格式

Output n+1n+1 numbers. The ii -th number is the answer of k=i1k=i-1 .

输入输出样例

  • 输入#1

    4
    1 2
    3 2
    2 4

    输出#1

    0 3 4 5 6
  • 输入#2

    1

    输出#2

    0 0

说明/提示

Consider the first example. When k=2k=2 , Tenzing can paint vertices 11 and 22 black then the value of edge (1,2)(1,2) is 0, and the values of other edges are all equal to 22 . So the value of that tree is 44 .

首页