PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000003. Hợp tập hợp (Union-Find)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hợp tập hợp (Union-Find)

Union-Find

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn elements numbered from 00 to n−1n-1. Initially, each element forms a separate set. Process operations that merge sets and ask whether two elements belong to the same set.

Input

The first line contains two integers n,qn,q. Each of the next qq lines has one of the following forms:

  • = a b: merge the sets containing aa and bb.
  • ? a b: check whether aa and bb belong to the same set.

Output

For each ? query, print yes if the elements belong to the same set and no otherwise, one answer per line.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1501\le n\le 150; 0≤q≤1500\le q\le 150; 0≤a,b<n0\le a,b<n.
  • Subtask 2 (30 points): 1≤n≤100001\le n\le 10000; 0≤q≤100000\le q\le 10000; 0≤a,b<n0\le a,b<n.
  • Subtask 3 (50 points): 1≤n≤10000001\le n\le 1000000; 0≤q≤10000000\le q\le 1000000; 0≤a,b<n0\le a,b<n.

Examples

Input

10 4
? 1 3
= 1 8
= 3 8
? 1 3

Output

no
yes

Explanation

Initially 1 and 3 are separate. Merging 1–8 and 3–8 puts all three into one set, giving yes.