#P9544. [湖北省选模拟 2023] 调和 / concoct
[湖北省选模拟 2023] 调和 / concoct
Problem Description
Xiao C is a pharmacist. To make a certain potion, she needs to find some herbs on the S Continent.
The S Continent can be modeled as an unrooted tree with vertices, and each vertex has one kind of herb. The property of each herb can be described by a triple , where , , and are all positive integers.
If Xiao C obtains herbs with properties , she may choose any non-negative real numbers that are not all , and harmonize these herbs into a potion with properties .
Now Xiao C needs to collect herbs on the S Continent. Specifically, she needs to choose a connected subgraph (a connected block) on the tree, and obtain all herbs on the vertices inside it. Given the desired potion property , please find the minimum possible size of the connected block such that Xiao C can use the obtained herbs to harmonize a potion with property .
Input Format
The input has lines.
The first line contains four positive integers .
The next lines each contain three positive integers , representing the properties of the herb on node .
The next lines each contain two integers and , indicating that there is an edge connecting and in the tree.
It is guaranteed that the given edges form a tree.
It is guaranteed that there are no two completely identical herbs, but it is allowed that some herb has exactly the same property as the required potion.
It is guaranteed that for all herbs, .
Output Format
Output one integer in a single line, the required answer.
4 2 2 3
1 1 5
3 2 2
3 3 1
2 4 1
1 2
2 3
2 4
3
8 3 269 1729
607 777 617
549 717 735
341 672 988
5 601 1395
846 263 892
796 954 251
243 144 1614
978 430 593
2 1
3 2
4 1
5 4
6 2
7 1
8 5
-1
Hint
Sample 1 Explanation
For the first sample, you can choose the connected block containing vertices , , and , and take as respectively. Then you can obtain a potion with properties $(\dfrac{1}{2} + \dfrac{3}{2},\dfrac{1}{2} + \dfrac{3}{2},\dfrac{5}{2} + \dfrac{1}{2}) = (2,2,3)$.
Subtasks
For all testdata, it is guaranteed that , .

- 2023.8.25 Added one set of hack data.
Translated by ChatGPT 5