#P15048. [UOI 2022 II Stage] 树 2

    ID: 16977 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>二分2022背包 DP树形 DPUOI(乌克兰)

[UOI 2022 II Stage] 树 2

Problem Description

Cossack Moustache saw a tree on his way home from the railway, and came up with a problem.

You are given a tree with nn vertices, and each edge has a weight. Initially, all vertices are white. We call an edge a bright edge if and only if it connects two white vertices. Please answer mm queries:

  • What is the minimum number of vertices that need to be recolored to black so that the sum of weights of all bright edges does not exceed kik_i?

Please help Cossack Moustache solve this problem.

Input Format

The first line contains three integers nn, mm, and gg (1≤n≤3 0001 \leq n \leq 3\,000, 1≤m≤2⋅1051 \leq m \leq 2 \cdot 10^5, 0≤g≤60 \leq g \leq 6), which represent the number of vertices, the number of queries, and the subtask ID, respectively.

In the next n−1n - 1 lines, each line contains three integers uiu_i, viv_i, and cic_i (1≤vi,ui≤n1 \leq v_i, u_i \leq n, 1≤ci≤1051 \leq c_i \leq 10^5), which describe an edge between the two vertices and its weight.

The fourth line contains mm integers k1,k2,…,kmk_1, k_2, \dots, k_m (0≤ki≤1090 \leq k_i \leq 10^9).

Output Format

Output mm integers x1,x2,…,xmx_1, x_2, \dots, x_m, where xix_i is the answer to the ii-th query.

3 5 0
1 2 3
1 3 2
3 5 1 2 0
1 0 1 1 1
4 4 0
1 3 10
2 1 15
1 4 50
75 50 72 19
0 1 1 1
5 8 0
1 4 5
2 1 18
1 3 9
3 5 27
5 15 7 19 20 58 35 27
2 2 2 2 2 1 1 1

Hint

Sample Explanation

In the first sample, if ki≥5k_i \geq 5, we can keep all vertices white. Then all edges are bright edges, and the sum of their weights is 55. If ki≤4k_i \leq 4, we can recolor vertex 11 to black, so there will be no bright edges, and thus the sum of weights is 00. In both cases, the sum of weights of bright edges does not exceed kik_i, and the number of recolored vertices is minimal.

Scoring

  • (5 points): m=1m = 1; the answer is guaranteed to be at most 11.
  • (9 points): m=1m = 1; the answer is guaranteed to be at most 22.
  • (28 points): ui=vi−1u_i = v_i - 1; n≤200n \leq 200.
  • (14 points): m=1m = 1; n≤10n \leq 10.
  • (21 points): n≤200n \leq 200.
  • (23 points): No additional constraints.

Translated by DeepSeek V3.

Translated by ChatGPT 5