Codeforces Round #264 (Div. 2)E(裸的树询问)
来源:互联网 发布:js中给文本框赋值 编辑:程序博客网 时间:2024/05/16 18:06
Caisa is now at home and his son has a simple task for him.
Given a rooted tree with n vertices, numbered from 1 to n (vertex 1 is the root). Each vertex of the tree has a value. You should answer qqueries. Each query is one of the following:
- Format of the query is "1 v". Let's write out the sequence of vertices along the path from the root to vertex v: u1, u2, ..., uk (u1 = 1; uk = v). You need to output such a vertex ui that gcd(value of ui, value of v) > 1 and i < k. If there are several possible vertices ui pick the one with maximum value of i. If there is no such vertex output -1.
- Format of the query is "2 v w". You must change the value of vertex v to w.
You are given all the queries, help Caisa to solve the problem.
The first line contains two space-separated integers n, q (1 ≤ n, q ≤ 105).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2·106), where ai represent the value of node i.
Each of the next n - 1 lines contains two integers xi and yi (1 ≤ xi, yi ≤ n; xi ≠ yi), denoting the edge of the tree between vertices xiand yi.
Each of the next q lines contains a query in the format that is given above. For each query the following inequalities hold: 1 ≤ v ≤ n and1 ≤ w ≤ 2·106. Note that: there are no more than 50 queries that changes the value of a vertex.
For each query of the first type output the result of the query.
4 610 8 4 31 22 33 41 11 21 31 42 1 91 4
-112-11
- Codeforces Round #264 (Div. 2)E(裸的树询问)
- 树的直径 Codeforces Round #260 (Div. 2)E
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #264 (Div. 2) A,B,C,D,E
- 线段树Codeforces Round #163 (Div. 2)E
- Codeforces Round#225 div.2E Propagating tree 线段树
- Codeforces Round #353 (Div. 2) E 线段树+dp
- Codeforces Round #271 (Div. 2) E 离散化+线段树
- Codeforces Round #321 (Div. 2)E 线段树+字符串hash
- Codeforces Round #262 (Div. 2)E(贪心+暴搜)
- Codeforces Round #257 (Div. 2)E(数论+构造)
- Codeforces Round #256 (Div. 2)E(DFS暴搜)
- Codeforces Round #FF (Div. 2)E(线段树成段更新)
- Codeforces Round #265 (Div. 2)E(数位dp)
- Codeforces Round #254 (Div. 2)E(线段树懒标记)
- Codeforces Round #281 (Div. 2)E(数学)
- Codeforces Round #249 (Div. 2)E(构造)
- Codeforces Round #291 (Div. 2)E(DP+矩阵)
- 代码补全
- BBC 野性中国
- velocity
- 腾讯2014校园招聘笔试题
- Android_ UEventObserver_监听USB插拔
- Codeforces Round #264 (Div. 2)E(裸的树询问)
- 学习资料(持续更新)
- android获取路径
- LeetCode Gas Station
- IOS面试题大全
- [综合面试] 2014校招暑假实习生面经(阿里、百度offer)
- 赋予root权限
- Linux下安装和使用MySQL
- lua 5.1 ==> 5.2