最小生成樹 克魯斯卡爾方法

2021-09-11 13:47:39 字數 708 閱讀 7105

原文出自:

個人非常喜歡這段**,不是特別難,但是又新學到了東西。思路還特別清晰。 給這個博主膜拜了。

有n個城市,你要把他們用隧道連起來,問最少修多少公尺的隧道。

#include#include#include#include#include#include#include#include#include#define inf 0x3f3f3f3f

using namespace std;

struct d //存邊的資訊 };

struct cmp};

int pre[105];

int flag;

double board[105][2];

int edge;

double lenth;

int find(int a) //找祖先

int judge(int a,int b) //判斷是在乙個集合

return 0;}

int main()

for(int i=0 ; i}

while(edge < n-1) //找到n-1條邊後結束

}printf("case #%d:\n",++flag);

printf("the minimal distance is: %.2f\n",lenth);

} return 0;

}

最小生成樹 克魯斯卡爾演算法

c node.h檔案 儲存頂點資訊 class c node c node c node c node p node c node c node c node c node char p data node.h檔案,儲存邊資訊 include class link node link node li...

最小生成樹( 克魯斯卡爾演算法)

name author date 01 12 14 20 17 description 最小生成樹 克魯斯卡爾演算法 關於並查集的演算法,參見 一種簡單而有趣的資料結構 並查集 include include define maxn 1000 最大頂點數量 define max 20000 最大邊數...

克魯斯卡爾 最小生成樹集錦

狀態是1的兩個分量直接聯通,然後套模板。include include include include include include include include include include using namespace std define maxn 1e 9 int pa 10000 ...