#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 nn vertices, and each vertex has one kind of herb. The property of each herb can be described by a triple (x,y,z)(x,y,z), where xx, yy, and zz are all positive integers.

If Xiao C obtains nn herbs with properties (x1,y1,z1),(x2,y2,z2)(xn,yn,zn)(x_1,y_1,z_1), (x_2,y_2,z_2) \ldots (x_n,y_n,z_n), she may choose any nn non-negative real numbers a1,a2ana_1,a_2 \ldots a_n that are not all 00, and harmonize these herbs into a potion with properties (aixi,aiyi,aizi)(\sum a_i x_i,\sum a_i y_i,\sum a_i z_i).

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 (a,b,c)(a,b,c), 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 (a,b,c)(a,b,c).

Input Format

The input has 2n2n lines.

The first line contains four positive integers n,a,b,cn,a,b,c.

The next nn lines each contain three positive integers xi,yi,zix_i,y_i,z_i, representing the properties of the herb on node ii.

The next n1n-1 lines each contain two integers uu and vv, indicating that there is an edge connecting uu and vv 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, xi+yi+zi=a+b+cx_i + y_i + z_i = a + b + c.

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 11, 22, and 33, and take a1,a2,a3a_1,a_2,a_3 as 12,0,12\dfrac{1}{2},0,\dfrac{1}{2} 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 1n5×1041 \leq n \leq 5 \times 10^4, 1a,b,c,xi,yi,zi2×1091 \leq a,b,c,x_i,y_i,z_i \leq 2 \times 10^9.

  • 2023.8.25 Added one set of hack data.

Translated by ChatGPT 5