`int find(int a,vector&s)

{

if(s[a]==-1)

return a;

else

return find(s[a],s);

}

void unionag(int x,int y,vector&s)

{

int pa=find(x,s);

int pb=find(y,s);

s[pb]=pa;

}

int Solution::solve(int A, vector &B, vector &C)

{

if(B.size()==0||C.size()==0)

return 1;

else

{

vectorset(A+1,-1);

for(int i=0;i<B.size();i++)

{

if(find(B[i],set)!=find(C[i],set))

unionag(B[i],C[i],set);

else

return 0;

}

```
}
return 1;
```

}`es here.