#DSU0000096. Tái cơ cấu công ty (Restructuring Company)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tái cơ cấu công ty (Restructuring Company)
Restructuring Company
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A company has employees numbered through . Initially every employee is in a separate department. Process operations in order: 1 x y merges the departments containing employees and ; 2 x y merges all departments containing employees with indices in (where ); 3 x y asks whether employees and belong to the same department. Merging departments never changes employee indices.
Input
The first line contains . Each following line contains three integers .
Output
For each query of type 3, print YES if the employees share a department, otherwise print NO.
Subtasks
- Subtask 1 (20 points): , , , ; for , .
- Subtask 2 (30 points): , , , ; for , .
- Subtask 3 (50 points): , , , ; for , .
Examples
Input
8 6
3 2 5
1 2 5
3 2 5
2 4 7
2 1 2
3 1 7
Output
NO
YES
YES
Explanation
Employees and initially belong to different departments. After merging, they share one; the interval merge connects employee to that group.