poj2395 Kruskal最小生成樹

2021-06-21 01:05:49 字數 521 閱讀 5352

/**

* poj2395 最小生成樹 kruskal演算法(加邊法)

* 就是個最小生成樹,只是記錄的是最大邊的邊長而已。環路檢測可以用並查集。並查集好多次忘了要用父點做為操作點了,wa了好多次

*/#include #include using namespace std;

struct roadr[10001];

int n,m;

int father[2001];

int points[2001];

int max_len=0;

bool cmp(const road &a,const road &b)

int min(int a,int b)

}fa = getfather(r[i].a);

fb = getfather(r[i].b);

if(fa != fb)}}

printf("%d\n",max_len);

return 0;

}

POJ 2395 解題報告

題意 找到最小生成樹里的最大邊。思路 只需要將裸板子中,最小生成樹一直累加邊權的語句sum edge i w 更改為 if edge i w max max edge i w 最後輸出max即可。本人ac include include include include include include...

poj 2395 prime的遞迴實現

求最小水桶的大小,每到達乙個農村就能把水桶補滿。可見是用生成最小樹,求最大邊。關於prime個人感覺用遞迴實現會少乙個for的時間。本題的坑 輸入邊的時候要找最小的,不然會出錯。1 include2 include3 using namespace std 4const int inf 0x3f3f...

POJ 2395 Out of Hay 最小生成樹

usaco 2005 march silver 題目大意 有n 2 2000 個農場,m 1 10000 條通路連通各個農場,長度不超109,要求遍歷全部的農場,且每走1單位長度就要消耗一單位水,每到乙個農場可以把自己的水充滿,求最小的水箱容量。樣例輸入 3 3 1 2 23 2 3 1000 1 ...