#P4115. Qtree4

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

Qtree4

题目背景

#欢迎提供更强的数据,本题目支持无限加数据(可私信,百度网盘地址)

#数据范围和spoj略有不同

题目描述

给出一棵边带权的节点数量为n的树,初始树上所有节点都是白色。有两种操作:

C x,改变节点x的颜色,即白变黑,黑变白

A,询问树中最远的两个白色节点的距离,这两个白色节点可以重合(此时距离为0)。

输入格式

In the first line there is an integer N (N <= 100000)

In the next N-1 lines, the i-th line describes the i-th edge: a line with three integers a b c denotes an edge between a, b of value c (-1000 <= c <= 1000)

In the next line, there is an integer Q denotes the number of instructions (Q <= 200000)

In the next Q lines, each line contains an instruction "C a" or "A"

输出格式

For each "A" operation, write one integer representing its result. If there is no white node in the tree, you should write "They have disappeared.".

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