#BZOJ1103. [POI2007] 大都市 MEG

[POI2007] 大都市 MEG

题目描述

有一棵节点数为 nn 的树,给定 m+n1m + n - 1 组询问,每组询问有两种操作。

  1. A x y,将 xx 节点和 yy 节点间的边权改为 00,每条边会被修改恰好一次。

  2. W x,求 11 号点到 xx 号点路径上的边权和。

初始所有边权值都为 11

输入格式

In the first line of the standard input there is a single integer nn (1n250 0001\le n\le 250\ 000),denoting the number of villages in Byteotia. The following n1n-1 lines contain descriptions of the roads, in the form of two integers aa,bb (1a<bn1\le a\lt b \le n) separated by a single space, denoting the numbers of villages connected with a road. Inthe next line there is a single integer mm(1m250 0001\le m\le 250\ 000),denoting the number of trips Byteasar has made.

The following n+m1n+m-1 lines contain descriptions of the events, in chronological order:

A description of the form "A aa bb"(for a<ba\lt b) denotes a country road between villages aa and bb beingtransformed into a motorway in that particular moment.

A description of the from "W aa" denotes Byteasar's trip from Bitburg to village aa.

输出格式

Your programme should write out exactly mm integers to the standard output, one a line, denoting the numberof country roads Byteasar has travelled during his successive trips.

样例

5
1 2
1 3
1 4
4 5
4
W 5
A 1 4
W 5
A 4 5
W 5
W 2
A 1 2
A 1 3
2
1
0
1