#P9555. 「CROI · R1」浣熊的阴阳鱼
「CROI · R1」浣熊的阴阳鱼
Background
In the past, yin and yang were created by heaven and earth, vast and profound; today, time is carved into memory, following like a shadow.
Between flowing water and falling flowers, there is playful joy in the mood of the Yin-Yang Tree; through seas turning into fields, there is an unforgettable brilliance in the Yin-Yang Memories.
Yin fish, yang fish... with the leisure of writing about the sun and moon, preserving the raccoon’s comfort, yet no longer existing...
The little raccoon CleverRaccoon, together with the last instant of yin and yang, smiles through tears...
Problem Description
Each node of a tree has yin fish or yang fish hanging on it (represented by respectively). At some moment, they may transform into each other due to genetic mutation.
The little raccoon CleverRaccoon walks along a chain of this tree, carrying a basket that can hold fish. When the fish at his current node has the opposite type to some fish in the basket, he will combine these fish into yin-yang fish and eat it. If the basket is not full, he will put the fish at the current node into the basket.
There are two types of operations:
- The yin/yang fish on a node undergoes a genetic mutation and becomes the other type of yin/yang fish.
- Help the smart little raccoon CleverRaccoon compute: when he walks along some chain on this tree, how many yin-yang fish he can eat.
Input Format
The first line contains two positive integers and , representing the number of nodes, and the total number of updates and queries.
The second line contains integers, representing the type of fish hanging on each node.
The next lines each contain two positive integers , indicating that there is an edge between nodes and .
The next lines are in the format 1 u or 2 u v.
If the format is 1 u, it means the fish on node undergoes genetic mutation.
If the format is 2 u v, it means querying how many yin-yang fish the little raccoon CleverRaccoon can eat on the simple path from to .
Output Format
For each query, output one integer per line, representing the number of yin-yang fish that the little raccoon CleverRaccoon can eat.
9 3
1 1 1 0 1 1 0 0 0
1 2
2 3
3 4
3 5
1 6
6 7
7 8
7 9
2 9 4
1 9
2 4 9
3
2
Hint
Constraints
This problem uses bundled Subtask testdata.
- Subtask 0 (10 points): .
- Subtask 1 (15 points): .
- Subtask 2 (15 points): the depth of the tree is less than .
- Subtask 3 (60 points): no special constraints.
For all testdata: .
Translated by ChatGPT 5