#abc311h. Ex - Many Illumination Plans
Ex - Many Illumination Plans
Score : points
问题描述
存在一棵有 个顶点的根树 ,顶点编号为 到 。根节点为顶点 ,顶点 的父节点为 。
每个顶点都有两个非负整数值,分别称为美感值和权重。顶点 的美感值和权重分别为 和 。
另外,每个顶点被涂成红色或蓝色。顶点 的颜色由一个整数 表示:如果 ,则顶点 涂成红色;如果 ,则顶点 涂成蓝色。
对于顶点 ,令 为以下问题的答案。
设 是以 为根节点的 的子树。
你可以对 零次或多次执行以下操作序列。(这些操作不会影响未被删除的顶点的美感值、权重或颜色。)
- 选择除根节点外的一个顶点 ,设其父节点为 。
- 对于每条以 为父节点端点的边,执行以下操作:
- 让 为该边除 外的另一个端点。删除这条边,并用一条新边连接 和 ,其中 位于父节点一侧。
- 删除顶点 ,以及连接 和 的边。
当满足所有以下条件时,经过一些操作后可得到的作为 的根树被称为良好根树。
- 在 中的每条边上,两端点的颜色都不同。
- 顶点的总权重不超过 。
找到良好根树中顶点的最大可能总美感值。
计算出所有的 , , , 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a rooted tree with vertices numbered to . The root is vertex , and the parent of vertex is .
Each vertex has two non-negative integer values called beauty and weight. The beauty and weight of vertex are and , respectively.
Additionally, each vertex is painted red or blue. The color of vertex is represented by an integer : vertex is painted red if , and blue if .
For vertex , let be the answer to the following problem.
Let be the rooted tree that is the subtree of rooted at .
You can perform the following sequence of operations on zero or more times. (The operations do not affect the beauties, weights, or colors of the vertices that are not being deleted.)
- Choose a vertex other than the root. Let be the parent of .
- For each edge whose endpoint on the parent side is , do the following:
- Let be the endpoint of the edge other than . Delete the edge and connect and with a new edge, with on the parent side.
- Delete the vertex , and the edge connecting and .
A rooted tree that can be obtained as after some operations is called a good rooted tree when all of the following conditions are satisfied.
- For every edge in , the edge's endpoints have different colors.
- The vertices have a total weight of at most .
Find the maximum possible total beauty of the vertices in a good rooted tree.
Find all of .
Constraints
- is or .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain .
Sample Input 1
4 10
1 2 2
2 1 0
4 2 1
6 8 0
7 4 1
Sample Output 1
9
10
6
7
For , choosing and then changes as shown in the figure, making it a good rooted tree. The total beauty of the vertices in this tree is , which is the maximum among all good rooted trees, so .
For , choosing changes as shown in the figure, making it a good rooted tree. The total beauty of the vertices in this tree is , which is the maximum among all good rooted trees, so .
Sample Input 2
5 5
1 2 2 3
1 1 0
10 1 1
100 1 0
1000 1 1
10000 1 1
Sample Output 2
11001
10110
10100
1000
10000
Sample Input 3
20 100
1 2 1 1 1 6 6 5 1 7 9 4 6 4 15 16 8 2 5
887945036308847 12 0
699398807312293 20 1
501806283312516 17 0
559755618233839 19 1
253673279319163 10 1
745815685342299 11 1
251710263962529 15 0
777195295276573 15 0
408579800634972 17 0
521840965162492 17 1
730678137312837 18 1
370007714721362 14 1
474595536466754 17 0
879365432938644 15 0
291785577961862 20 0
835878893889428 14 1
503562238579284 10 0
567569163005307 18 1
368949585722534 15 0
386435396601075 16 0
Sample Output 3
5329161389647368
1570154676347343
501806283312516
2665577865131167
1418696191276572
3952333977838189
982388401275366
1344764458281880
778587515356334
521840965162492
730678137312837
370007714721362
474595536466754
879365432938644
1631226710430574
1339441132468712
503562238579284
567569163005307
368949585722534
386435396601075
update @ 2024/3/10 08:52:36