当前位置:网站首页>Floyed "suggestions collection"
Floyed "suggestions collection"
2022-07-02 15:46:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
#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 Shortest path ,d2 The largest side is the smallest ,d3 Min edge Max .
void init()
{
scanf("%d%d%d",&n,&m);
for(int i=1;i<=n;i++)// initial value
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;
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/147719.html Link to the original text :https://javaforall.cn
边栏推荐
- Soul torture, what is AQS???
- Golang MD5 encryption and MD5 salt value encryption
- 【LeetCode】486-预测赢家
- Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
- 数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
- 6091. Divide the array so that the maximum difference is K
- [leetcode] 19 delete the penultimate node of the linked list
- 【LeetCode】200-岛屿数量
- 6092. 替换数组中的元素
- 【LeetCode】1140-石子游戏II
猜你喜欢
![[leetcode] 1162 map analysis](/img/9a/d04bde0417d4d5232950a4e260eb91.png)
[leetcode] 1162 map analysis

已知两种遍历序列构造二叉树

《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究

03. Preliminary use of golang

Two traversal sequences are known to construct binary trees

爱可可AI前沿推介(7.2)

自定义异常

Why does the system convert the temp environment variable to a short file name?

二叉树前,中,后序遍历

Xpt2046 four wire resistive touch screen
随机推荐
PyObject 转 char* (string)
【LeetCode】1020-飞地的数量
[leetcode] 167 - sum of two numbers II - enter an ordered array
高考录取分数线爬虫
[experience cloud] how to get the metadata of experience cloud in vscode
解决BASE64Encoder报错的问题
2303. Calculate the total tax payable
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
[salesforce] how to confirm your salesforce version?
Why does the system convert the temp environment variable to a short file name?
[leetcode] 876 intermediate node of linked list
/bin/ld: 找不到 -lcrypto
《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量
【LeetCode】19-删除链表的倒数第N个结点
目标检测—利用labelimg制作自己的深度学习目标检测数据集
士官类学校名录
Ant group's large-scale map computing system tugraph passed the national evaluation
【LeetCode】283-移动零
Leetcode skimming -- sum of two integers 371 medium
【LeetCode】695-岛屿的最大面积