1 Star 0 Fork 0

Hic/personal_ACM_code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
graphTheory.h 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
Hic 提交于 2020-07-26 17:08 . 初次上传
#include<algorithm>
#include<climits>
using namespace std;
//ȫ·㷨 Floyd
class CFloyd
{
static const unsigned N = 110;
unsigned adjacencyMatrix[N][N];
unsigned n;
unsigned shortestDis[N][N];
public:
//start from 1
void init(unsigned n_)
{
unsigned i, j;
n = n_;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
adjacencyMatrix[i][j] = INT_MAX;
}
void setAWay(unsigned a, unsigned b, unsigned weight)
{
if (weight < adjacencyMatrix[a][b]) {
adjacencyMatrix[a][b] = weight;
adjacencyMatrix[b][a] = weight;
}
}
void calculate()
{
unsigned i, j, k;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
shortestDis[i][j] = adjacencyMatrix[i][j];
for (k = 1; k <= n; ++k)
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
/*if (shortestDis[i][k] < INT_MAX&& shortestDis[k][j] < INT_MAX)*/shortestDis[i][j] = min(shortestDis[i][j], shortestDis[i][k] + shortestDis[k][j]);
}
unsigned shortestDistance(unsigned from, unsigned to)
{
return shortestDis[from][to];
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hic_0757/personal_ACM_code.git
[email protected]:hic_0757/personal_ACM_code.git
hic_0757
personal_ACM_code
personal_ACM_code
master

搜索帮助