Prim(添点法)
1. 任选一点(一般选1), 作为切入点,设其与最小生成树的距离为0(实际上就是选一个点,将此树实体化),.
2. 在所有未选择的点中选出与最小生成树距离最短的, 累计其距离, 并标为已选. 若都选择了, 则得到了最小生成树(的总路长).
3. 更新与此点相邻的点"与最小生成树的距离".返回2.
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
#define N 1003
#define inf 0x3f3f3f3f
struct node {
int v, w;
node () {}
node(int _v, i......
阅读全文