An apple tree can be represented as a tree with nodes, where each node is an apple. Good apples are denoted by , while rotten apples are denoted by . There are events of the following types:
- - all apples in the interval become good;
- - all apples in the interval become rotten;
- - all apples in the interval change their state .
Task
Farmer John wonders after each event which are the two good apples and , such that the number of nodes located on the path between and is maximized.
Input data
The first line will contain the numbers and , as described above.
The following lines will contain the edges of the tree.
The next line will contain a binary string of length , where represents the state of apple ( = good, = rotten).
The following lines will contain the numbers , , and , representing operation .
Output data
You will output lines, line containing the numbers and , representing the good apples located at the maximum distance from each other. If there is not at least one good apple, print 0 0
.
Constraints and clarifications
- If there are multiple solutions, any of them will be accepted
- The apples chosen don't have to be distinct
- If no good apple exists,
0 0
should be printed - It is recommended to use fast I/O
- If you have issues with the constant, you can try using pragmas
- For test cases worth points:
- For other test cases worth points:
- For other test cases worth points:
- For other test cases worth points: the tree is of the form
- For other test cases worth points: there are no updates of type or
- For other test cases worth points: there are no updates of type
- For other test cases worth points:
Example
stdin
9 7
1 2
1 3
2 7
7 8
7 9
3 4
3 5
3 6
100011101
1 2 3
2 5 7
3 1 9
3 1 4
3 2 6
1 1 9
2 1 9
stdout
6 9
3 9
5 8
5 8
4 8
8 5
0 0
Explanation
Initially, the tree looks like this:
After the first event, the tree looks like this:
In this case, one solution is , with a distance of . Another solution could have been .
After the second event, the tree looks like this:
In this case, the only solution is , with a distance of .
At the end of all events, the tree looks like this:
In this case, there is no good apple, so the solution will be .