为什么merge写s[x]=find(y);会20pts wa
而s[find(x)]=find(y);就能ac?
附代码:
#include <iostream>
using namespace std;
#define MAX 10010
int s[MAX],n,m,op,x,y;
int find(int x)
{
if(s[x]!=x)
s[x]=find(s[x]);
return s[x];
}
inline void merge(int x,int y)
{
s[find(x)]=find(y);
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 1;i<=n;i++)
s[i]=i;
while(m--)
{
cin >> op >> x >> y;
switch(op)
{
case 1:
merge(x,y);
break;
default:
cout << (find(x)==find(y)?'Y':'N') << endl;
}
}
return 0;
}