luogu#P4787. [BalkanOI 2018] Minmaxtree
[BalkanOI 2018] Minmaxtree
Problem Description
Translated from BalkanOI 2018 Day 1 T3 “Minmaxtree”.
There is an unweighted tree with nodes, numbered . You need to assign a weight to each edge to make it a weighted tree. The weighted tree must satisfy conditions. There are two types of conditions:
- The maximum edge weight on the path from node to node is .
- The minimum edge weight on the path from node to node is .
It is guaranteed that the values in these conditions are all distinct.
Please construct such a tree and output the weight of each edge.
Input Format
The first line contains an integer .
In the next lines, each line contains two integers, indicating an edge connecting two nodes.
Line contains an integer .
In the next lines, each line starts with a letter or , followed by three integers .
Output Format
Output lines. Each line contains three integers separated by spaces, meaning an edge in the weighted tree has weight .
4
1 2
2 3
3 4
3
M 1 2 1
m 1 4 0
M 2 3 100
3 2 100
1 2 1
4 3 0
Hint
Subtask #1 (7 points): .
Subtask #2 (22 points): Only condition type 1, and no condition type 2.
Subtask #3 (29 points): All paths from to given in condition type 1 are pairwise edge-disjoint. All paths from to given in condition type 2 are also pairwise edge-disjoint.
Subtask #4 (42 points): No other restrictions.
For all testdata, , .
Thanks to Planet6174 for providing the translation.
Translated by ChatGPT 5