UniTN CP Training 2020 - #2

Start

2020-07-15 06:00 AKDT

UniTN CP Training 2020 - #2

End

2020-07-22 06:00 AKDT
The end is near!
Contest is over.
Not yet started.
Contest is starting in -70 days 5:43:06

168:00:00

0:00:00

Problem DUnion-Find

Input

The first line of input consists of two integers $N$ and $Q$, where $1 \le N \le 1\, 000\, 000$ is the number of elements in the base set and $0 \le Q \le 1\, 000\, 000$ is the number of operations. Then follow $Q$ lines, one per operation. There are two types of operations:

• = $a$ $b$” indicate that the sets containing $a$ and $b$ are joined

• ? $a$ $b$” is a query asking whether $a$ and $b$ belong to the same set

In both cases, $a$ and $b$ are distinct integers between $0$ and $N-1$.

Output

For each query output a line containing “yes” if $a$ and $b$ are in the same set, and “no” otherwise.

Sample Input 1 Sample Output 1
10 4
? 1 3
= 1 8
= 3 8
? 1 3

no
yes

Sample Input 2 Sample Output 2
4 5
? 0 0
= 0 1
= 1 2
= 0 2
? 0 3

yes
no