#Q143. 「一本通 4.5 练习 3」染色
「一本通 4.5 练习 3」染色
Description
Original source: SDOI 2011
Given a tree with nodes and operations, there are two types of operations:
-
Color all nodes on the path from node to node with a specified color;
-
Query the number of color segments on the path from node to node , where consecutive nodes with the same color are considered as one segment. For example,
112221consists of three segments:11,222, and1.
Write a program to execute these operations sequentially.
Input Format
The first line contains two integers and , representing the number of nodes and operations, respectively;
The second line contains positive integers representing the initial colors of the nodes;
The next several lines each contain two integers and , indicating an undirected edge between node and node ;
The subsequent lines each describe an operation:
-
C a b cdenotes a coloring operation, coloring all nodes (including and ) on the path from node to node with color ; -
Q a bdenotes a query operation, asking for the number of color segments on the path from node to node (including and ).
Output Format
For each query operation, output the result on a separate line.
Sample 1
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
3
1
2
Constraints and Hints
For of the data, , and all colors are integers within the range .