#P6869. [COCI 2019/2020 #5] Putovanje
[COCI 2019/2020 #5] Putovanje
Problem Description
You are given a tree with nodes, numbered from to .
You will visit each node in increasing order of its label.
Traversing edges in the tree costs money. For the -th edge, there is a single-use ticket (can only be used once) with price , and a multi-use ticket (can be used an unlimited number of times) with price . During your trip, you may traverse an edge multiple times, so a multi-use ticket can sometimes be more cost-effective.
Please find the minimum total cost required to visit from to .
Input Format
-
The first line: a positive integer .
-
The next lines describe the edges: four positive integers , meaning there is an edge connecting and whose single-use ticket costs and multi-use ticket costs .
Output Format
Output one line with one positive integer: your answer.
4
1 2 3 5
1 3 2 4
2 4 1 3
10
4
1 4 5 5
3 4 4 7
2 4 2 6
16
5
1 2 2 3
1 3 2 3
1 4 2 3
1 5 2 3
11
Hint
Sample #1 Explanation
- : multi-use ticket, cost .
- : uses the previously bought multi-use ticket, no cost; single-use ticket, cost .
- : single-use ticket, cost ; uses the previously bought multi-use ticket, no cost; single-use ticket, cost .
- Total cost is .
Constraints
This problem uses bundled testdata.
-
For of the testdata, .
-
For another of the testdata, each town is directly connected to at most two other towns.
-
For all testdata, , , .
Notes
Translated from COCI2019-2020 CONTEST #5 T4 Putovanje.
Translated by ChatGPT 5