#P3979. 遥远的国度

    ID: 2914 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树倍增最近公共祖先,LCA树链剖分,树剖

遥远的国度

Description

zcwwzdjn is hunting down zhx, and zhx has fled to a distant kingdom. When zcwwzdjn is about to enter the distant kingdom to continue the pursuit, the guardian RapiD blocks his way. He must complete a task before he can enter the distant kingdom and continue the chase.

Here is the problem: the distant kingdom has nn cities. These cities are connected by some roads and they form a tree. The kingdom has a capital, and we can regard this capital as the root of the whole tree; however, the capital may change to another city at any time. Each city has a defense value; the ii-th city's defense value is valival_i. Sometimes RapiD will set the defense values of all cities on the path between two cities to a certain value.

RapiD wants to know, at some moment, if we regard the capital as the root of the whole tree, then what is the minimum defense value among all cities in the subtree rooted at some city.

Since RapiD cannot solve this, he stopped zcwwzdjn hoping he could help. But zcwwzdjn still needs to hunt down zhx, so this important problem has been handed over to you.

Input Format

Line 11: two integers n mn\ m, representing the number of cities and the number of operations.

Lines 22 to nn: each line contains two integers u vu\ v, meaning there is a road between city uu and city vv.

Line n+1n+1: nn integers; the ii-th integer is the initial defense value valival_i of the ii-th city.

Line n+2n+2: one integer idid, meaning the initial capital is idid.

Lines n+3n+3 to n+m+2n+m+2: first there is an integer optopt.

  • If opt=1opt=1, then there is an integer idid, meaning the capital is updated to idid.
  • If opt=2opt=2, then there are three integers x y vx\ y\ v, meaning the defense values of all cities on the path x yx\ y are set to vv.
  • If opt=3opt=3, then there is an integer idid, meaning you need to query the minimum defense value in the subtree rooted at city idid (with the current capital regarded as the root of the whole tree).

Output Format

For each opt=3opt=3 operation, output one line containing the minimum defense value in the corresponding subtree.

3 7
1 2
1 3
1 2 3
1
3 1
2 1 1 6
3 1
2 2 2 5
3 1
2 3 3 4
3 1
1
2
3
4

Hint

For 20%20\% of the testdata, n1000,m1000n\le 1000,m\le 1000.

For another 10%10\% of the testdata, n100000,m100000n\le 100000,m\le 100000, and updates are guaranteed to be point updates.

For another 10%10\% of the testdata, n100000,m100000n\le100000,m \le 100000, and the tree is guaranteed to be a chain.

For another 10%10\% of the testdata, n100000,m100000n\le 100000,m\le100000, and there are no operations that change the capital.

For 100%100\% of the testdata, $1 \leq n\le 100000,1 \leq m \le 100000,0<val_i<2^{31}$.

Translated by ChatGPT 5