当前位置:网站首页>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
边栏推荐
- 【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
- 2303. Calculate the total tax payable
- PTA 天梯赛习题集 L2-001 城市间紧急救援
- 【LeetCode】977-有序数组的平方
- Bing.com網站
- 【LeetCode】200-岛屿数量
- 彻底弄懂浏览器强缓存和协商缓存
- 6091. Divide the array so that the maximum difference is K
- Loss function and positive and negative sample allocation: Yolo series
- For the problem that Folium map cannot be displayed, the temporary solution is as follows
猜你喜欢

Bing. Site Internet

怎样从微信返回的json字符串中截取某个key的值?

【LeetCode】1162-地图分析

Leetcode skimming - remove duplicate letters 316 medium

Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!

Leetcode skimming -- sum of two integers 371 medium

03.golang初步使用

LeetCode刷题——奇偶链表#328#Medium

树-二叉搜索树

SQL stored procedure
随机推荐
Bing. Site Internet
College entrance examination admission score line climbing
【LeetCode】1254-统计封闭岛屿的数量
16_ Redis_ Redis persistence
Name of institution approved in advance
2303. 计算应缴税款总额
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
LeetCode刷题——去除重复字母#316#Medium
How to intercept the value of a key from the JSON string returned by wechat?
Leetcode skimming -- incremental ternary subsequence 334 medium
03.golang初步使用
SQL transaction
[leetcode] 189 rotation array
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
6090. 极大极小游戏
18_ Redis_ Redis master-slave replication & cluster building
Custom exception
[leetcode] 577 reverse word III in string
13_ Redis_ affair
[leetcode] 1140 stone game II