Start

2019-10-27 16:00 UTC

Problem Set 5

End

2019-11-11 16:00 UTC
The end is near!
Session is over.
Not yet started.
Session is starting in -43 days 0:07:19

Time elapsed

360:00:00

Time remaining

0:00:00

Problem A
Union-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