hdu1598 find the most comfortable road 并查集

hdu1598 find the most comfortable road 并查集

#include
#include
using namespace std;
const int maxn=200+10;  //point
const int maxm=1000+10; //edge
int p[maxn],r[maxn],n,m;
struct node
{
    int s,e;    //start end
    int w;      //speed
}edge[maxm];
void make()
{
    memset(p,-1,sizeof(p));
    memset(r,0,sizeof(r));
}
int findset(int x)
{
    int px=x,tmp;
    while (p[px]!=-1)   px=p[px];
    while (px!=x) {
        tmp=p[x];
        p[x]=px;
        x=tmp;
    }
    return px;
}
int unionset(int x,int y)
{
    x=findset(x),y=findset(y);
    if(x==y)    return -1;
    if(r[x]>r[y])
    {
        p[y]=x;return x;
    }
    else
    {
        p[x]=y;
        if(r[x]==r[y])  r[y]++;
        return y;
    }
}
bool cmp(node a,node b)
{
    return a.w


 
   
 
  
 
  
 
  
 
  
 
  
 
 

你可能感兴趣的:(hdu1598 find the most comfortable road 并查集)