1348:【例4-9】城市公交网建设问题
发布时间
阅读量:
阅读量
例4-9
// 示例代码 Prim算法
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 105; // 定义常量 N,表示数组大小
int n, e, x, y, w;
int g[N][N]; // 保存图的邻接矩阵
int ans[N]; // 记录当前最小生成树中每个点的父亲节点编号
bool v[N]; // 标记哪些点已经在MST中
struct nod {
int to, w;
bool operator < (const nod &other) const { // 重载小于号运算符,使得该结构体对象可被优先队列使用(小根堆)
return w > other.w; // 按权值从小到大排序
}
};
void prim() {
全部评论 (0)
还没有任何评论哟~
