Problem C
Crystalfly
Paimon is catching crystalflies on a tree, which are a
special kind of butterflies in Teyvat. A tree is a connected
graph consisting of
Pixiv ID: 93964680
There are initially
At the beginning of the
-
Move to one of the adjacent vertices of her current vertex and stay there before the beginning of the next second (if the crystalflies in the destination will disappear at the end of that second she can still catch them).
-
Stay still in her current vertex before the beginning of the next second.
Calculate the maximum number of crystalflies Paimon can
catch in
Input
There are multiple test cases. The first line of the input
contains an integer
The first line contains an integer
The second line contains
The third line contains
For the next
It’s guaranteed that the sum of
Output
For each test case output one line containing one integer indicating the maximum number of crystalflies Paimon can catch.
Explanation
For the first sample test case, follow the strategy below.
-
During the
-th second-
Paimon arrives at vertex
; -
Paimon catches
crystalfly; -
Crystalflies in vertices
and are disturbed.
-
-
During the
-st second-
Paimon arrives at vertex
; -
Paimon catches
crystalflies.
-
-
During the
-nd second-
Paimon arrives at vertex
; -
Crystalflies in vertex
disappears.
-
-
During the
-rd second-
Paimon arrives at vertex
; -
Crystalflies in vertices
and are disturbed.
-
-
During the
-th second-
Paimon arrives at vertex
; -
Paimon catches
crystalflies; -
Crystalflies in vertex
disappears.
-
For the second sample test case, the optimal strategy is the
same with the first sample test case. Crystalflies in vertex
Sample Input 1 | Sample Output 1 |
---|---|
2 5 1 10 100 1000 10000 1 2 1 1 1 1 2 1 3 2 4 2 5 5 1 10 100 1000 10000 1 3 1 1 1 1 2 1 3 2 4 2 5 |
10101 10111 |