Union find easy


#1
int findP(int check [],int x)

{
while(check[x]!=-1)
x=check[x];
return x;
}
int Solution::solve(int A, vector<vector > &B)
{
int check[A+1];
memset(check,-1,sizeof(check));
for(int i=0;i<B.size();i++)
{
int x=findP(check,B[i][0]);
int y=findP(check,B[i][1]);
if(x==y)
return 1;
check[x]=y;
}
return 0;
}


#2

can you let me know why check[y]=x instead of check[x]=y results in TLE?