#P3250. [HNOI2016] 网络

    ID: 2299 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016线段树湖南最近公共祖先,LCA树链剖分,树剖

[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:

  1. A new data exchange request appears between two servers.
  2. A data exchange request ends.
  3. 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. 2n1052 \le n \le 10^5, 1m2×1051 \le m \le 2\times 10^5, and all other input values do not exceed 10910^9.

Input Format

The first line contains two positive integers n,mn,m, denoting the numbers of servers and events, respectively. Server IDs start from 11, so the nn servers are numbered 1,2,3,,n1,2,3,\cdots,n.

The next n1n-1 lines each contain two positive integers u,vu,v, describing a tree edge. uu and vv are server IDs.

The next mm lines describe each event in chronological order; that is, the ii-th line (i=1,2,3,,mi=1,2,3,\ldots,m) describes the event that occurs at time ii. The first number type\mathrm{type} denotes the event type, with three types in total:

  1. If type=0\mathrm{type}=0, then three positive integers a,b,va,b,v follow, meaning that a data exchange request with importance vv appears between servers aa and bb.
  2. If type=1\mathrm{type}=1, then a positive integer tt follows, meaning that the data exchange request that appeared at time tt (i.e., the tt-th event) ends.
  3. If type=2\mathrm{type}=2, then a positive integer xx follows, meaning that server xx fails at this moment.

Each event with type=2\mathrm{type}=2 is a query, i.e., “When server xx fails, what is the maximum importance among the requests that are not affected?”

Output Format

For each event with type=2\mathrm{type}=2 (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 1-1.

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, (a,b;t,v)(a,b;t,v) denotes a request that appears at time tt between servers aa and bb with importance vv:

For the first query (at time 11), there is no request, so output 1-1.

For the fourth query (at time 66), there are two requests (8,13;2,3)(8,13;2,3) and (9,12;3,5)(9,12;3,5). Both paths pass through server 22, so output 1-1.

For the fifth query (at time 88), there are three requests (8,13;2,3)(8,13;2,3), (9,12;3,5)(9,12;3,5), and (10,12;7,1)(10,12;7,1). Only the request (10,12;7,1)(10,12;7,1) does not pass through server 22, so output its importance 11.

For the last query (at time 2323), there are three requests (9,5;12,6)(9,5;12,6), (9,12;16,4)(9,12;16,4), and (10,5;17,7)(10,5;17,7). When server 33 fails, only the request (9,5;12,6)(9,5;12,6) does not pass through server 33, so output 66.

upd 2016.5.20\text{upd 2016.5.20}:Added one set of Hack\text{Hack} testdata.

Translated by ChatGPT 5