当前位置:网站首页>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
边栏推荐
猜你喜欢
Experiment collection of University Course "Fundamentals of circuit analysis". Experiment 5 - Research on equivalent circuit of linear active two terminal network
Leetcode question brushing - parity linked list 328 medium
【LeetCode】1162-地图分析
[leetcode] 417 - Pacific Atlantic current problem
Redux - detailed explanation
Thoroughly understand browser strong cache and negotiation cache
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics
Wechat Alipay account system and payment interface business process
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
随机推荐
PTA ladder game exercise set l2-001 inter city emergency rescue
Pytoch saves tensor to Mat file
6091. 划分数组使最大差为 K
The task cannot be submitted after the installation of flick is completed
6.12 critical moment of Unified Process Platform
睿智的目标检测23——Pytorch搭建SSD目标检测平台
Ant group's large-scale map computing system tugraph passed the national evaluation
(5) Flink's table API and SQL update mode and Kafka connector case
[network security] network asset collection
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
【LeetCode】876-链表的中间结点
[leetcode] 189 rotation array
2279. Maximum number of backpacks filled with stones
Leetcode skimming -- count the number of numbers with different numbers 357 medium
College entrance examination score line climbing
《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量
(4) Flink's table API and SQL table schema
[leetcode] 19 delete the penultimate node of the linked list
【idea】推荐一个idea翻译插件:Translation「建议收藏」
/bin/ld: 找不到 -lcrypto