#P15842. [Bulgarian NOI 2024] 最长路径 / longest
[Bulgarian NOI 2024] 最长路径 / longest
Problem Description
You are given a weighted tree with vertices. Its edges are (weight ), (weight ), , (weight ). Write a program to support queries, where each query is one of the following two types:
- Type 1: Given , find the maximum path length from vertex to any vertex , under the constraint that the path from to must not pass through any of the specified vertices .
- Type 2: Given , modify the weight of the -th edge to .
Input Format
Read an integer from the first line of standard input. The next lines each contain three integers , describing an edge connecting vertices and with weight . The next line contains an integer . Each of the following lines first gives the query type (1 or 2):
- If the type is 1, then read , , and integers .
- If the type is 2, then read and .
Output Format
For each type 1 query, print the required maximum path length on a separate line to standard output.
5
1 2 1
1 4 2
2 3 3
2 5 4
10
1 1 0
1 2 0
1 3 0
1 4 0
1 5 0
1 1 1 5
1 1 1 2
2 1 100
1 2 0
1 2 4 1 3 4 5
5
4
7
7
7
4
2
102
0
Hint
Sample 1 Explanation
In the queries, the target vertices that need to be found are, in order, .
Constraints
- For all ,
- For all ,
Subtasks
| Subtask | Points | Additional Constraints |
|---|---|---|
| The degree of each vertex is at most | ||
| There are no type queries | ||
| None |
You can obtain the points for a subtask only if you pass all testdata for that subtask.
Translated by Qwen3.5-397B-A17B.
Translated by ChatGPT 5