hoj2676 relation

/*This Code is Submitted by billforum for Problem 2676 at 2012-02-11 17:27:50*/
#include   
#include   
using namespace std;  
  
const int N=5000;
int root[N+5],rank[N+5];
void init()
{
        for(int i=1;i<=N;i++)
        {
                root[i]=i;
                rank[i]=1;
        }
        return;
}
int findroot(int x)
{
        if(root[x]==x) return x;
        else
        {
                //root[x]=findroot(root[x]);
                //return root[x];
                return root[x]=findroot(root[x]);
        }
}
void rel(int x,int y)
{
        int r1,r2;
        r1=findroot(x);
        r2=findroot(y);
        //root[r1]=r2;
        ///if(r1==r2) return;
        //else root[r1]=r2;
        
        
        if(r1==r2) return;
        else
          {
           if(rank[r1]==rank[r2]) 
                   {root[r1]=r2; 
                    rank[r2]++;
                   }
            else  if(rank[r1]>m1>>m2;
                   scanf("%d%d",&m1,&m2);
                   rel(m1,m2);
           }
           for(int j=1;j<=Q;j++)
           {
                   int q1,q2;
                  // cin>>q1>>q2;
                  scanf("%d%d",&q1,&q2);
                   if(qury(q1,q2)) //cout<<"yes"<

 

转载于:https://www.cnblogs.com/wuzhibin/archive/2012/02/11/2346861.html

你可能感兴趣的:(hoj2676 relation)