hdu3047之並查集

2021-06-13 19:50:54 字數 403 閱讀 8960

#include#include#include#include#include#include#include#include#include#define inf 99999999

using namespace std;

const int max=50000+10;

const int mod=300;

int father[max],dist[max],sum;

void makeset(int num)

}int findset(int v)

void union(int x,int y,int l)

else

}int main()

cout<} return 0;

}

HDU 3047 帶權並查集

衝突的條件是 用乙個dist陣列來儲存節點到根的距離,這個距離在路徑壓縮的時候更新一下,dist x dist parent x 然後 在合併時,令r1 find u r2 find v 於是合併時就有parent r2 r1,dist r2 dist u w dist v include incl...

HDU3938 並查集 並查集

先按邊權值排個序,每次加入一條邊,用並查集,關鍵看懂題。include include include include using namespace std const int maxn 10010 int n,m,q struct edge edges maxn 5 inline int cmp...

hdu3635之並查集

include include include include include include include include include include define inf 99999999 using namespace std const int max 10000 10 father ...