#P3637. QTREE6 - Query on a tree VI

QTREE6 - Query on a tree VI

QTREE6 - Query on a tree VI

题面翻译

题目描述

给你一棵 nn 个点的树,编号 1n1\sim n。每个点可以是黑色,可以是白色。初始时所有点都是黑色。下面有两种操作:

  • 0 u:询问有多少个节点 vv 满足路径 uuvv 上所有节点(包括 uu)都拥有相同的颜色。
  • 1 u:翻转 uu 的颜色。

输入格式

第一行一个整数 nn

接下来 n1n-1 行,每行两个整数表示一条边。

接下来一行一个整数 mm 表示操作次数。

接下来 mm 行,每行两个整数分别表示操作类型和被操作节点。

输出格式

对每个询问操作输出相应的结果。

题目描述

You are given a tree (an acyclic undirected connected graph) with nn nodes. The tree nodes are numbered from 11 to nn. Each node has a color, white or black. All the nodes are black initially. We will ask you to perform some instructions of the following form:

  • 0 u: ask for how many nodes are connected to uu, two nodes are connected if all the node on the path from uu to vv (inclusive uu and vv) have the same color.
  • 1 u: toggle the color of uu (that is, from black to white, or from white to black).

输入格式

The first line contains a number nn that denotes the number of nodes in the tree (n1n-1 lines), there will be two numbers (u,v)(u, v) that describes an edge of the tree (1u,vn1\leq u, v\leq n). The next line contains a number mm denoting number of operations we are going to process (mm lines) describe an operation (t,u)(t, u) as we mentioned above (0t1,1un0\leq t\leq 1, 1 \leq u\leq n).

输出格式

For each query operation, output the corresponding result.

样例 #1

样例输入 #1

5
1 2
1 3
1 4
1 5
3
0 1
1 1
0 1

样例输出 #1

5
1

提示

1n,m1051\leq n,m\leq 10^5