#ds902. 染色
染色
Coloring
Problem Source
SDOI2011
Problem Description
Given an unrooted tree with nodes and operations, of two types:
- Color all nodes on the path from node to node (including and ) with colour .
- Query the number of colour segments on the path from node to node .
A colour segment is defined as a maximal run of consecutive nodes of the same colour. For example, 112221 consists of three colour segments: 11, 222, 1.
Input Format
The first line contains two integers separated by a space: (the number of nodes) and (the number of operations).
The second line contains integers separated by spaces; the -th integer is the initial colour of node .
The next lines each contain two integers separated by a space, meaning there is an edge between node and node .
The next lines each describe one operation, in the following format:
Each line begins with a character indicating the type of operation.
- If is
C, it is a colouring operation; after a space there are three integers separated by spaces, meaning colour all nodes on the path from to with colour . - If is
Q, it is a query operation; after a space there are two integers , meaning query the number of colour segments on the path from to .
It is guaranteed that .
Output Format
For each query operation, output one line containing one integer: the answer.
Sample Input
6 5
2 2 1 2 1 1
1 2
1 3
2 4
2 5
2 6
Q 3 5
C 2 1 1
Q 3 5
C 5 1 2
Q 3 5
Sample Output
3
1
2