并查集模板

来源:互联网 发布:tom围棋 mac 编辑:程序博客网 时间:2024/06/16 00:55
int find(int x)  {      int r = x;      while(father[r]!=r)      r = father[r];      return r;  }  /* int find(int x) {     if(father[x] == x)     return x;     else     return father[x] =find(father[x]); } */    void join(int x,int j)  {      int fx = find(x),fy = find(y);      if(fx!=fy)      father[fx] = fy;  }    void Union(int x,int y)  {      int rx,ry;      rx = find(x);      ry = find(y);      father[rx] = ry;  }