#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;
vector<int> H; // h(x)
void LoadTopo(vector<vector<int>> &topo, int nodeNum)
{
topo.resize(nodeNum + 1);
int u, v, w;
// while (cin >> u >> v >> w) {
// topo[u].push_back(v);
// }
while (~scanf("%d %d %d", &u, &v, &w)) {
topo[u].push_back(v);
}
return;
}
void ReverseTopo(const vector<vector<int>> &topo, vector<vector<int>> &revTopo)
{
revTopo.resize(topo.size());
for (int u = 0; u < topo.size(); ++u) {
for (int v : topo[u]) {
revTopo[v].push_back(u);
}
}
}
constexpr int TOPO_LINK_DEFAULT_COST = 1;
void Dijkstra(const vector<vector<int>> &topo, vector<int> &cost, int src)
{
using P = pair<int, int>;
priority_queue<P, vector<P>, greater<P>> que;
cost.resize(topo.size());
fill(cost.begin(), cost.end(), INF);
cost[src] = 0;
que.push((P){cost[src], src});
while (!que.empty()) {
P curP = que.top();
que.pop();
int u = curP.second;
if (cost[u] < curP.first) {
continue;
}
for (int v : topo[u]) {
if (cost[v] > cost[u] + TOPO_LINK_DEFAULT_COST) {
cost[v] = cost[u] + TOPO_LINK_DEFAULT_COST;
que.push((P){cost[v], v});
}
}
}
}
void PrintPath(const vector<int> &path)
{
cout << "path cost
基于A*算法的KSP问题求解
最新推荐文章于 2024-08-10 01:00:11 发布
这篇博客介绍如何利用A*算法解决KSP问题,提供了4000个点之间的最短路径计算,并详细说明了性能表现。通过Python生成输入数据并用C++进行处理,步骤包括将Python代码输出重定向到in.txt文件,然后编译运行C++代码。
摘要由CSDN通过智能技术生成