当前位置:网站首页>floyed「建议收藏」
floyed「建议收藏」
2022-07-02 12:15:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=405;
const int inf=4000005;
int d1[maxn][maxn],n,m,g[maxn][maxn],d2[maxn][maxn],d3[maxn][maxn];//d1最短路径,d2最大边最小,d3最小边最大。
void init()
{
scanf("%d%d%d",&n,&m);
for(int i=1;i<=n;i++)//初值
for(int j=1;j<=n;j++)
{
if(i==j) g[i][j]=0;
else g[i][j]=inf;
}
for(int i=1;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
g[x][y]=z;
g[y][x]=z;
}
}
void floyd()
{
memcpy(d1,g,sizeof(d1));
memcpy(d2,g,sizeof(d2));
memcpy(d3,g,sizeof(d3));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(d2[i][j]==inf)
d2[i][j]=-inf;
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(d1[i][k]+d1[k][j]<d1[i][j])
d1[i][j]=d1[i][k]+d1[k][j];
int x=min(d2[i][k],d2[k][j]);
d2[i][j]=max(d2[i][j],x);
int t=max(d3[i][k],d3[k][j]);
d3[i][j]=min(d3[i][j],t);
}
}
int main()
{
init();
floyd();
return 0;
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/147719.html原文链接:https://javaforall.cn
边栏推荐
- folium地图无法显示的问题,临时性解决方案如下
- 【LeetCode】977-有序数组的平方
- List of sergeant schools
- 【Leetcode】167-两数之和II -输入有序数组
- YOLOV5 代码复现以及搭载服务器运行
- Evaluation of embedded rz/g2l processor core board and development board of Feiling
- [leetcode] 1905 statistics sub Island
- 03.golang初步使用
- Two traversal sequences are known to construct binary trees
- [network security] network asset collection
猜你喜欢

. Solution to the problem of Chinese garbled code when net core reads files

PTA 天梯赛习题集 L2-001 城市间紧急救援

Wechat Alipay account system and payment interface business process

Leetcode skimming -- sum of two integers 371 medium

Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568

Pytoch saves tensor to Mat file

5. Practice: jctree implements the annotation processor at compile time

20_ Redis_ Sentinel mode

17_ Redis_ Redis publish subscription

6.12 critical moment of Unified Process Platform
随机推荐
6092. 替换数组中的元素
【网络安全】网络资产收集
[leetcode] 167 - sum of two numbers II - enter an ordered array
士官类学校名录
密码学基础知识
17_ Redis_ Redis publish subscription
【LeetCode】1905-统计子岛屿
[leetcode] 1254 - count the number of closed Islands
LeetCode刷题——奇偶链表#328#Medium
Deux séquences ergodiques connues pour construire des arbres binaires
党史纪实主题公益数字文创产品正式上线
LeetCode刷题——递增的三元子序列#334#Medium
[leetcode] 977 - carré du tableau ordonné
Solve the problem of frequent interruption of mobaxterm remote connection
【LeetCode】417-太平洋大西洋水流问题
04.进入云原生后的企业级应用构建的一些思考
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
[leetcode] 1905 statistics sub Island
【LeetCode】189-轮转数组
Case introduction and problem analysis of microservice