# P3038 [USACO11DEC]牧草种植Grass Planting

• 647通过
• 1.3K提交
• 题目提供者 FarmerJohn2
• 评测方式 云端评测
• 标签 动态规划,动规,dp 树链剖分,树剖 线段树 USACO 2011 高性能
• 难度 提高+/省选-
• 时空限制 1000ms / 128MB
• 提示：收藏到任务计划后，可在首页查看。

## 题目描述

Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on the roads between pastures. Farmer John loves Bessie very much, and today he is finally going to plant grass on the roads. He will do so using a procedure consisting of M steps (1 <= M <= 100,000).

At each step one of two things will happen:

• FJ will choose two pastures, and plant a patch of grass along each road in between the two pastures, or,

Farmer John is a very poor counter -- help him answer Bessie's questions!

给出一棵n个节点的树，有m个操作，操作为将一条路径上的边权加一或询问某条边的权值。

## 输入输出格式

输入格式：

* Line 1: Two space-separated integers N and M

* Lines 2..N: Two space-separated integers describing the endpoints of a road.

* Lines N+1..N+M: Line i+1 describes step i. The first character of the line is either P or Q, which describes whether or not FJ is planting grass or simply querying. This is followed by two space-separated integers A_i and B_i (1 <= A_i, B_i <= N) which describe FJ's action or query.

输出格式：

* Lines 1..???: Each line has the answer to a query, appearing in the same order as the queries appear in the input.

## 输入输出样例

输入样例#1： 复制
4 6
1 4
2 4
3 4
P 2 3
P 1 3
Q 3 4
P 1 4
Q 2 4
Q 1 4

输出样例#1： 复制
2
1
2


提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。