#P4219. [BJOI2014] 大融合
[BJOI2014] 大融合
Description
Xiaoqiang wants to build a communication system across isolated planets. This communication system is a tree that connects nodes.
Edges of the tree are added one by one.
At any given time, the load of an edge is the number of simple paths in its current connected tree that pass through it.

For example, in the figure above, there are edges in total. The load of edge is , because there are six simple paths , , , , , that pass through .
Now, as edges are added, your task is to dynamically answer Xiaoqiang’s queries about the load of certain edges.
Input Format
The first line contains two integers , the number of planets and the number of operations. Planets are numbered starting from .
Each of the next lines is in one of the following formats:
A x yAdd an edge between and . It is guaranteed that and were previously disconnected.Q x yQuery the load on edge . It is guaranteed that there is an edge between and .
Output Format
Output several integers, each being the answer to a query, one per line.
8 6
A 2 3
A 3 4
A 3 8
A 8 7
A 6 5
Q 3 8
6
Hint
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号