College is a major part of life, it gives you new friends life experiences and other stuff, our chef has joined as a teacher in college and he is watching the fresher’s closely. There are N students in a class and they don’t know each other. Slowly they start talking to each other and form groups of friends. Chef wants to keep track of all the events for answering questions about the class to the principal.
There are 2 types of queries :
0 A B : The student with number A becomes friends with student with number B
1 X Y: You have to tell whether the student number X and student number Y are friends or not.
Note : If A is friends with B, and B is friends with C. That implies C is friends with A.
Input:
First line will contain N, the number of students in class.
Next line contains Q, number of queries.
Next Q lines contain 3 integers as per the query above.
Output:
For each query, of type 2 Print “YES”, if they are friends and “NO”, if they are not.
Constraints
1≤N≤100000
1≤Q≤100000
1≤A,B,X,Y≤N
Subtasks
30 points : 1≤N,Q≤1000
70 points : Original Constraints
Sample Input:
3
4
0 1 2
1 1 3
0 2 3
1 1 3
Sample Output:
NO
YES
1 2 3 4
|
I thought of doing it with a vector<set<ll>> or using map but there is some error in my
programs and i think there must be some easier better way to do it I just can't think what
can you help me please
|