hdu1879 kruskal求最小生成樹

2021-06-08 11:43:25 字數 427 閱讀 4604

源**:

#include

#include

#include

#include

using namespace std;

typedef struct edge

edge;

edge e[5000];

int city[101];

bool comp(const edge &a,const edge &b)

int find_set(int n)

bool merge(int s1,int s2)

int main()

sort(e,e+m,comp);

for(i=0;iif(count==n-1)break;

}printf("%d\n",sum);

}return 0;

}

hdu 1879題解報告

題目大意 給定n個點以及n n 1 2條邊的資訊,然後讓我們求出最短的路程使得所有點相通。題目解析 其實就是乙個最小生成樹的問題,這裡我用的是prime演算法。實現 include include include include include include include using names...

繼續暢通工程 hdu 1879

include 2243673 2010 03 24 20 56 41 accepted 1879 375ms 320k 1070 b c 悔惜晟 include 修改了三次終於ac,為何就是 的效率不高 include include using namespace std int s 4991 ...

hdu 1879 繼續暢通工程

include include include typedef structedge edge input 5050 int cost 5050 int parent 5050 int cmp const void a,const void b int root int n int kruskal ...