#P9304. 「DTOI-5」3-1

    ID: 10053 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>树形数据结构O2优化深度优先搜索 DFS树的遍历

「DTOI-5」3-1

Background

— It seems that something called the "Sun" used to exist.

The legend goes like this: white flames gave off dazzling light, and the sky was a clear, pure blue.

It is said that the "Great War" started by the gods and their creations turned the land into scorched earth, and ashes covered the sky.

The ashes struck the power of the stars flowing in the sky — the "Elf Corridor" — which began to glow and dyed the sky red.

And that red color covered every piece of land where mutual slaughter still continued.

Or perhaps it was the planet’s own wail of grief and the blood it shed...

Under the blood-red sky, there was only — blue ash drifting down.

Come back 3579, my proudest faith/ll

Problem Description

Rick discovered an ancient "Divine Tree" within sight.

The Divine Tree is a tree with nn positions that contain magical devices. After an initial "survey", there are n1n - 1 magical edges. The ii-th edge (1in1)(1 \leq i \leq n - 1) connects two devices ui,viu_i, v_i, and it is guaranteed that uiviu_i \neq v_i and 1ui,vin1 \leq u_i, v_i \leq n. These two devices can be traveled between bidirectionally in 11 unit of time. It is guaranteed that with only these n1n - 1 edges, every device is reachable from every other device.

In addition, there are n1n - 1 special edges. For each device i[2,n]i \in [2, n], you can teleport instantly to device 11 with cost 00 time. All special edges can be used only once in total.

Rick starts at device 11. Now, given the structure of this "Divine Tree", Rick wants to study as many devices as possible within some amount of time. We assume that studying a device only requires arriving at that device, and costs no extra time.

You need to compute as quickly as possible, for all k[1,n]k \in [1, n], if Rick wants to study exactly kk different devices, and then return to device 1\bm 1, what is the minimum time needed.

Input Format

The first line contains an integer nn.

The next n1n - 1 lines each contain two integers ui,viu_i, v_i.

Output Format

Output nn lines in total. The ii-th line contains one integer, the answer for k=ik = i.

5
1 2
1 3
2 4
2 5
0
1
2
4
6
见下发的 hope/hope2.in
见下发的 hope/hope2.ans

Hint

[Sample Explanation 1\bm 1]

  • When k=1k = 1, Rick only needs to stay at device 11.
  • When k=2k = 2, Rick’s route can be 1211 \rightarrow 2 \Rightarrow 1.
  • When k=3k = 3, Rick’s route can be 12411 \rightarrow 2 \rightarrow 4 \Rightarrow 1.
  • When k=4k = 4, Rick’s route can be $1 \rightarrow 2 \rightarrow 4 \Rightarrow 1 \rightarrow 3 \rightarrow 1$.
  • When k=5k = 5, Rick’s route can be $1 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 5 \rightarrow 2 \rightarrow 4 \Rightarrow 1$.

[Sample Explanation 2\bm 2]

This testdata satisfies the properties of test points numbered 132013 \sim 20.

[Constraints and Conventions]

Test Point ID Special Restriction
121 \sim 2 n=3n = 3
343 \sim 4 n=5n = 5
565 \sim 6 n=100n = 100
787 \sim 8 n=1000n = 1000
9109 \sim 10 ui=1,vi=i+1u_i = 1, v_i = i + 1
111211 \sim 12 ui=i,vi=i+1u_i = i, v_i = i + 1
132013 \sim 20 No special restrictions

For all data, 1n1051 \leq n \leq 10^5, 1ui,vin1 \leq u_i, v_i \leq n.

Translated by ChatGPT 5