#P3250. [HNOI2016] 网络
[HNOI2016] 网络
Description
A simple network system can be described as an unrooted tree. Each node is a server. The data cable connecting servers is treated as a tree edge. When two servers exchange data, the data passes through all servers on the unique path connecting these two servers (including the two servers themselves).
Because this path is unique, if any server on the path fails and cannot operate normally, the data cannot be exchanged. In addition, each data exchange request has an importance value, and more important requests should clearly receive higher priority. Now, as the administrator of a network system, you need to monitor the system’s operating status. The system behavior is simple: at each time, exactly one of the following three events may occur:
- A new data exchange request appears between two servers.
- A data exchange request ends.
- A server fails. The system will repair it immediately after any failure. That is, right after the moment the failure occurs, this server is still normal. However, at the moment the failure occurs, it still affects data exchange requests that need to pass through this server.
Your task is to maintain, for each failure, the maximum importance value among the requests that are not affected. Note that if a data exchange request has already ended, it is not considered among the unaffected requests.
Note that a data exchange request may occur between a server and itself. , , and all other input values do not exceed .
Input Format
The first line contains two positive integers , denoting the numbers of servers and events, respectively. Server IDs start from , so the servers are numbered .
The next lines each contain two positive integers , describing a tree edge. and are server IDs.
The next lines describe each event in chronological order; that is, the -th line () describes the event that occurs at time . The first number denotes the event type, with three types in total:
- If , then three positive integers follow, meaning that a data exchange request with importance appears between servers and .
- If , then a positive integer follows, meaning that the data exchange request that appeared at time (i.e., the -th event) ends.
- If , then a positive integer follows, meaning that server fails at this moment.
Each event with is a query, i.e., “When server fails, what is the maximum importance among the requests that are not affected?”
Output Format
For each event with (i.e., a server failure), output one line with one integer, the maximum importance among the requests that are not affected. If there is currently no request, or all requests are affected, output .
13 23
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
6 10
6 11
7 12
7 13
2 1
0 8 13 3
0 9 12 5
2 9
2 8
2 2
0 10 12 1
2 2
1 3
2 7
2 1
0 9 5 6
2 4
2 5
1 7
0 9 12 4
0 10 5 7
2 1
2 4
2 12
1 2
2 5
2 3
-1
3
5
-1
1
-1
1
1
3
6
7
7
4
6
Hint
The tree given in the sample is shown below:

Explanations for some queries; in the explanations below, denotes a request that appears at time between servers and with importance :
For the first query (at time ), there is no request, so output .
For the fourth query (at time ), there are two requests and . Both paths pass through server , so output .
For the fifth query (at time ), there are three requests , , and . Only the request does not pass through server , so output its importance .
For the last query (at time ), there are three requests , , and . When server fails, only the request does not pass through server , so output .
:Added one set of testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号