Problem:
Score : 100 points

Problem Statement

You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.

0 u v: Add an edge (u, v).

1 u v: Print 1 if u and v are in the same connected component, 0 otherwise.

Constraints

1 \leq N \leq 200,000

1 \leq Q \leq 200,000

0 \leq u_i, v_i \lt N

Input

Input is given from Standard Input in the following format:

N Q
t_1 u_1 v_1
t_2 u_2 v_2
:
t_Q u_Q v_Q

出力

For each query of the latter type, print the answer.

Sample Input 1

4 7
1 0 1
0 0 1
0 2 3
1 0 1
1 1 2
0 0 2
1 1 3

Sample Output 1

0
1
0
1

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 1000000007
ll parent[200005];
ll getparent(ll x)
{
	if(x==parent[x])return parent[x];
	else return parent[x]=getparent(parent[x]);
}
void unite(int x,int y)
{
	ll spx=getparent(x);
	ll spy=getparent(y);
	if(spx!=spy)
		parent[spx]=spy;
}
int main()
{   
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	fast;
	ll n;
    cin>>n;
	for(int i=0;i<=n+1;i++)
		parent[i]=i;
    ll q;
    cin>>q;
    while(q--)
    {
    	int k;
    	cin>>k;
    	if(k==0)
    	{
    		int x,y;
    		cin>>x>>y;
    		unite(x,y);
    	}
    	else{
    		int x,y;
    		cin>>x>>y;
    		if(parent[x]==parent[y])
    			cout<<"1\n";
    		else
    			cout<<"0\n";
    	}
    }
	return 0;
}