Union Find On Codeforces

codeforces
graph
union-find

#1

Can you help me with this problem
here is my solution getting wa / I have used union find method `

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
int i,j,k=0,d,n=0,m,a,b,c,q,l,r;
cin>>n;
vector<int> x[1001],y[1001];
int arr[n+1];
for(i=0;i<=n;i++)
    arr*=i;
for(i=1;i<=n;i++){
    cin>>a>>b;
    if(x[a].size())
        arr*=x[a][0];
    else if(y**.size())
        arr*=y**[0];
    else {
        x[a].emplace_back(i);
        y**.emplace_back(i);
    }

}
    for(i=1;i<=n;i++)
        if(arr*==i)
            k++;
cout<<k-1<<"

";

return 0;
}

ps. I don’t know why codechef has so pathetic code sharing . use this linnk as an alternative for my solution code .