AT_abc460_g.Vertex Flip Query
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a tree with N vertices numbered 1 to N. The i-th edge connects vertices ai and bi. Each vertex i has a weight Wi and a color Ci∈{0,1}.
Process Q queries. There are three types of queries as follows.
1 v: Change Cv to 1−Cv for vertex v.2 v x: Change Wv to Wv+x for vertex v.3 v: Let c be the color of vertex v. Output the sum of weights of all vertices reachable from vertex v by traveling only through vertices of color c (including vertex v itself).
有一棵包含 N 个顶点的树,顶点编号为 1 到 N。第 i 条边连接顶点 ai 和 bi。每个顶点 i 具有权重 Wi 和颜色 Ci∈{0,1}。
处理 Q 个查询。查询共分以下三种类型:
1 v:将顶点 v 的颜色 Cv 修改为 1−Cv。2 v x:将顶点 v 的权重 Wv 修改为 Wv+x。3 v:设顶点 v 的颜色为 c,输出所有可通过仅经过颜色为 c 的顶点(包括顶点 v 自身)从顶点 v 到达的顶点的权重之和。
输入格式
The input is given from Standard Input in the following format, where queryi denotes the i-th query:
N Q
W1 W2 … WN
C1 C2 … CN
a1 b1
a2 b2
⋮
aN−1 bN−1
query1
query2
⋮
queryQ
Each query is given in one of the following formats:
1 v
2 v x
3 v
输入从标准输入中按以下格式给出,其中 queryi 表示第 i 个查询:
N Q
W1 W2 … WN
C1 C2 … CN
a1 b1
a2 b2
⋮
aN−1 bN−1
query1
query2
⋮
queryQ
每个查询以如下格式之一给出:
1 v
2 v x
3 v
输出格式
Let m be the number of type-3 queries given. Output m lines. The i-th line should contain the answer for the i-th type-3 query.
设给定的类型-3 查询数量为 m。输出 m 行,其中第 i 行应包含第 i 个类型-3 查询的答案。
输入输出样例
输入#1
5 9 1 10 100 1000 10000 0 0 0 0 0 1 2 2 3 3 4 2 5 3 1 1 2 3 1 3 2 3 3 1 3 1 2 2 1 1 3 5
输出#1
11111 1 10 1100 10012
输入#2
10 25 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 0 1 0 0 0 1 0 0 0 0 1 2 1 3 2 4 4 5 4 6 2 7 5 8 8 9 6 10 3 4 1 8 2 6 100000 3 3 1 3 1 7 1 7 1 7 3 8 2 1 1 2 6 100000 2 8 10000000 1 5 2 5 10000 1 9 2 7 1000000 1 7 2 10 1000000000 1 9 1 6 1 9 1 1 3 7 2 5 10000 3 6
输出#2
110011000 101 10000000 2000000 2000301000
说明/提示
Sample 1 Explanation:
For example, for the first query, the set of vertices reachable from vertex 1 by traveling only through vertices of color 0 is {1,2,3,4,5}.
Constraints
- 1≤N≤3×105
- 1≤Q≤2×105
- 1≤Wi≤109
- Ci∈{0,1}
- 1≤ai<bi≤N
- The input graph is a tree.
- 1≤v≤N
- 1≤x≤109
- All input values are integers.
样例 1 解释:
例如,对于第一个查询,仅通过颜色为 0 的顶点可达的、从顶点 1 出发的顶点集合为 {1,2,3,4,5}。
限制条件
- 1≤N≤3×105
- 1≤Q≤2×105
- 1≤Wi≤109
- Ci∈{0,1}
- 1≤ai<bi≤N
- 输入图是一棵树。
- 1≤v≤N
- 1≤x≤109
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?