#P9304. 「DTOI-5」3-1
「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 positions that contain magical devices. After an initial "survey", there are magical edges. The -th edge connects two devices , and it is guaranteed that and . These two devices can be traveled between bidirectionally in unit of time. It is guaranteed that with only these edges, every device is reachable from every other device.
In addition, there are special edges. For each device , you can teleport instantly to device with cost time. All special edges can be used only once in total.
Rick starts at device . 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 , if Rick wants to study exactly different devices, and then return to device , what is the minimum time needed.
Input Format
The first line contains an integer .
The next lines each contain two integers .
Output Format
Output lines in total. The -th line contains one integer, the answer for .
5
1 2
1 3
2 4
2 5
0
1
2
4
6
见下发的 hope/hope2.in
见下发的 hope/hope2.ans
Hint
[Sample Explanation ]
- When , Rick only needs to stay at device .
- When , Rick’s route can be .
- When , Rick’s route can be .
- When , Rick’s route can be $1 \rightarrow 2 \rightarrow 4 \Rightarrow 1 \rightarrow 3 \rightarrow 1$.
- When , Rick’s route can be $1 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 5 \rightarrow 2 \rightarrow 4 \Rightarrow 1$.
[Sample Explanation ]
This testdata satisfies the properties of test points numbered .
[Constraints and Conventions]
| Test Point ID | Special Restriction |
|---|---|
| No special restrictions |
For all data, , .
Translated by ChatGPT 5