#P2441. 角色属性树

    ID: 1438 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学树形结构枚举,暴力素数判断,质数,筛法

角色属性树

Description

The Xumeng Fan Club is an interesting organization with a hierarchical tree structure. There is a president, who directly supervises several vice presidents. Each vice president, in turn, directly supervises several department heads, and so on.

Each member has a "moe" attribute, which is the product of several prime "moe elements" (for example, the value of cat ears is 22, timid is 33, blonde is 55, yandere is 77, twin-tails is 1111, etc.).

For example, suppose a certain member has double cat ears and one timid trait; then her attribute value is 2×2×3=122\times 2\times 3=12.

Now, members care about the following question: for themselves, who is the nearest superior that shares at least one common moe element? For example, attribute values 2,4,6,452, 4, 6, 45 are all considered to share moe elements with the above member with attribute 1212.

However, a member may change their attribute at any time. Ah... what a hassle.

Input Format

The first line contains n,kn, k, the number of members and the number of queries.

The second line contains nn numbers, the attribute values of members 11 through nn.

The next n1n-1 lines each contain xi,yix_i, y_i, meaning xix_i is the supervisor of yiy_i.

Then kk lines follow, each of one of the two types:

1 ui1\ u_i:Query the nearest superior of member uiu_i that shares at least one moe element.

2 ui a2\ u_i\ a:Change the attribute value of uiu_i to aa.

Output Format

For each type 11 query, output the required member ID. If there is no such superior, output 1-1.

4 6
10 8 4 3
1 2
2 3
3 4
1 1
1 2
1 3
1 4
2 1 9
1 4
-1
1
2
-1
1

Hint

Constraints:

  • For 20%20\% of the testdata, there are no update operations.
  • For 50%50\% of the testdata, n100n\le 100, the number of updates <10<10.
  • For 100%100\% of the testdata, n200000n\le 200000, k<100000k<100000, the number of updates 50\le 50, and ai2311a_i\le 2^{31}-1.

UPD: The testdata are random; this might be a fake problem.

Translated by ChatGPT 5