当前位置:网站首页>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
边栏推荐
- 6092. 替换数组中的元素
- yolo格式数据集处理(xml转txt)
- [leetcode] 283 move zero
- Pytorch 保存tensor到.mat文件
- For the problem that Folium map cannot be displayed, the temporary solution is as follows
- 彻底弄懂浏览器强缓存和协商缓存
- LeetCode刷题——奇偶链表#328#Medium
- [leetcode] 167 - sum of two numbers II - enter an ordered array
- 【LeetCode】417-太平洋大西洋水流问题
- 【LeetCode】283-移动零
猜你喜欢
【LeetCode】1905-统计子岛屿
Redux - detailed explanation
Party History Documentary theme public welfare digital cultural and creative products officially launched
搭建自己的语义分割平台deeplabV3+
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
损失函数与正负样本分配:YOLO系列
SQL transaction
已知兩種遍曆序列構造二叉樹
Oracle primary key auto increment
怎样从微信返回的json字符串中截取某个key的值?
随机推荐
【LeetCode】977-有序數組的平方
Infra11199 database system
【LeetCode】1140-石子游戏II
MD5加密
【LeetCode】19-删除链表的倒数第N个结点
[leetcode] 19 delete the penultimate node of the linked list
【Salesforce】如何确认你的Salesforce版本?
15_ Redis_ Redis. Conf detailed explanation
2303. Calculate the total tax payable
[leetcode] 876 intermediate node of linked list
PTA ladder game exercise set l2-001 inter city emergency rescue
folium,确诊和密接轨迹上图
2303. 计算应缴税款总额
Loss function and positive and negative sample allocation: Yolo series
[leetcode] 577 reverse word III in string
Custom exception
[leetcode] 1254 - count the number of closed Islands
提前批院校名称
Name of institution approved in advance
[leetcode] 344 reverse string