#P15753. [JAG 2024 Summer Camp #3] Equal or Not Equal

[JAG 2024 Summer Camp #3] Equal or Not Equal

题目描述

There are NN integer variables a1,,aNa_1, \ldots, a_N. All the initial values are unspecified. You have to process MM events in order, each of which is an observation event, a change event or an inquiry event.

One kind of an observation event has the format,

1 x y\begin{aligned} &1 \ x \ y \end{aligned}

which represents that it is observed that axa_x and aya_y are equal. In other words, after this event it is guaranteed that these two variables have the same value unless there is a change event for either variable.

The other kind of an observation event has the format,

2 x y\begin{aligned} &2 \ x \ y \end{aligned}

which represents that it is observed that axa_x and aya_y are not equal.

A change event has the format,

3 x\begin{aligned} &3 \ x \end{aligned}

which represents that the value of axa_x changes to a different integer.

Finally, an inquiry event has the format,

4 x y\begin{aligned} &4 \ x \ y \end{aligned}

which asks whether axa_x and aya_y are equal. If it can be proven from all the past events that axa_x and aya_y are equal, you have to print Yes. Similarly, if it can be proven that axa_x and aya_y are not equal, you have to print No. If neither can be proven, you have to print Unknown.

输入格式

The input consists of a single test case of the following format, where all values in the input are integers.

$$\begin{aligned} &N \ M \\ &\text{event}_1 \\ &\vdots \\ &\text{event}_M \end{aligned} $$

The integer NN is the number of variables (1N1061 \leq N \leq 10^6). The integer MM is the number of events (1M500,0001 \leq M \leq 500,000). MM events are given in chronological order. The format of each event is explained above. In an observation event or an inquiry event, it is guaranteed that 1x<yN1 \leq x < y \leq N. In a change event it is guaranteed that 1xN1 \leq x \leq N.

At any point, it is guaranteed that there is at least one assignment to all NN variables that contradicts none of the given information.

输出格式

For each inquiry event, print Yes, No or Unknown followed by a newline.

4 11
1 1 2
4 1 2
2 3 4
4 3 4
4 1 3
1 1 3
4 1 3
4 1 4
3 1
4 1 3
4 1 4
Yes
No
Unknown
Yes
No
No
Unknown