#P4115. Qtree4

    ID: 3049 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>点分治二叉堆O2优化分治树链剖分,树剖概率论,统计

Qtree4

Description

You are given a tree with nn nodes, where each edge has a weight. Initially, all nodes are white. There are two types of operations:

  • C x: toggle the color of node xx; white becomes black, and black becomes white.
  • A: query the distance between the farthest two white nodes in the tree. These two white nodes may coincide (in which case the distance is 00).

Input Format

The first line contains a positive integer nn (n105n \le 10^5).

Each of the next n1n-1 lines contains three integers aa, bb, cc, representing an edge between nodes aa and bb with weight cc (c103|c| \le 10^3).

The next line contains a positive integer qq (q2×105q \le 2\times 10^5), the number of operations.

Each of the next qq lines contains one operation.

Output Format

For each A operation, if there are no white nodes in the tree, output a line with the string They have disappeared.. Otherwise, output a line with one integer, the distance between the farthest two white nodes in the tree.

3
1 2 1
1 3 1
7
A
C 1
A
C 2
A
C 3
A
2
2
0
They have disappeared.

Hint

Translated by ChatGPT 5