CF1628E.Groceries in Meteor Town

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mihai lives in a town where meteor storms are a common problem. It's annoying, because Mihai has to buy groceries sometimes, and getting hit by meteors isn't fun. Therefore, we ask you to find the most dangerous way to buy groceries so that we can trick him to go there.

The town has nn buildings numbered from 11 to nn . Some buildings have roads between them, and there is exactly 11 simple path from any building to any other building. Each road has a certain meteor danger level. The buildings all have grocery stores, but Mihai only cares about the open ones, of course. Initially, all the grocery stores are closed.

You are given qq queries of three types:

  1. Given the integers ll and rr , the buildings numbered from ll to rr open their grocery stores (nothing happens to buildings in the range that already have an open grocery store).
  2. Given the integers ll and rr , the buildings numbered from ll to rr close their grocery stores (nothing happens to buildings in the range that didn't have an open grocery store).
  3. Given the integer xx , find the maximum meteor danger level on the simple path from xx to any open grocery store, or 1-1 if there is no edge on any simple path to an open store.

输入格式

The first line contains the two integers nn and qq ( 2n,q31052 \le n, q \le 3\cdot 10^5 ).

Then follows n1n - 1 lines, the ii -th of which containing the integers uiu_i , viv_i , and wiw_i ( 1ui,vin,1wi1091 \le u_i, v_i \le n, \enspace 1 \le w_i \le 10^9 ) meaning there is two way road between building uiu_i and viv_i with meteor danger level wiw_i .

It is guaranteed that the given edges form a tree.

Then follows qq lines, the jj -th of which begin with the integer tjt_j ( 1tj31 \le t_j \le 3 ), meaning the jj -th query is of the tjt_j -th type.

If tjt_j is 11 or 22 the rest of the line contains the integers ljl_j and rjr_j ( 1ljrjn1 \le l_j \le r_j \le n ).

If tjt_j is 33 the rest of the line contains the integer xjx_j ( 1xjn1 \le x_j \le n ).

输出格式

For each query of the 33 rd type ( tj=3t_j = 3 ), output the maximum meteor danger level that is on some edge on the simple path from xjx_j to some open store, or 1-1 if there is no such edge.

输入输出样例

  • 输入#1

    6 9
    1 3 1
    2 3 2
    4 5 3
    4 6 4
    3 4 5
    3 1
    1 1 1
    3 1
    2 1 1
    1 5 6
    3 4
    2 6 6
    3 4
    3 1

    输出#1

    -1
    -1
    4
    3
    5

说明/提示

This is an illustration of the town given in the sample input.

In the first query, there are no open stores, so obviously there are no edges on the simple path from 11 to any open store, so the answer is 1-1 .

After the second and third queries, the set of open stores is {1}\{1\} . The simple path from 11 to 11 has no edges, so the answer for the 33 rd query is 1-1 .

After the fourth query, there are no open stores.

After the fifth and sixth queries, the set of open stores is {5,6}\{5, 6\} . In the sixth query, there are two paths from xj=4x_j = 4 to some open grocery store: 44 to 55 and 44 to 66 . The biggest meteor danger is found on the edge from 44 to 66 , so the answer for the 66 th query is 44 . This path is marked with red in the illustration.

After the rest of the queries, the set of open stores is {5}\{5\} . In the eighth query, the only path from xj=4x_j = 4 to an open store is from 44 to 55 , and the maximum weight on that path is 33 . This path is marked with green in the illustration.

In the ninth query, the only path from xj=1x_j = 1 to an open store is from 11 to 55 , and the maximum weight on that path is 55 . This path is marked with blue in the illustration.

首页