P15753 [JAG 2024 Summer Camp #3] Equal or Not Equal
Description
There are $N$ integer variables $a_1, \ldots, a_N$. All the initial values are unspecified. You have to process $M$ 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,
$$\begin{aligned} &1 \ x \ y \end{aligned}$$
which represents that it is observed that $a_x$ and $a_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,
$$\begin{aligned} &2 \ x \ y \end{aligned}$$
which represents that it is observed that $a_x$ and $a_y$ are not equal.
A change event has the format,
$$\begin{aligned} &3 \ x \end{aligned}$$
which represents that the value of $a_x$ changes to a different integer.
Finally, an inquiry event has the format,
$$\begin{aligned} &4 \ x \ y \end{aligned}$$
which asks whether $a_x$ and $a_y$ are equal. If it can be proven from all the past events that $a_x$ and $a_y$ are equal, you have to print **Yes**. Similarly, if it can be proven that $a_x$ and $a_y$ are not equal, you have to print **No**. If neither can be proven, you have to print **Unknown**.
Input Format
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 $N$ is the number of variables ($1 \leq N \leq 10^6$). The integer $M$ is the number of events ($1 \leq M \leq 500,000$). $M$ 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 $1 \leq x < y \leq N$. In a change event it is guaranteed that $1 \leq x \leq N$.
At any point, it is guaranteed that there is at least one assignment to all $N$ variables that contradicts none of the given information.
Output Format
For each inquiry event, print **Yes**, **No** or **Unknown** followed by a newline.