当前位置:网站首页>AcWing 1128. 信使 题解(最短路—Floyd)
AcWing 1128. 信使 题解(最短路—Floyd)
2022-07-02 18:27:00 【乔大先生】
AcWing 1128. 信使
floyd求最短路,三重循环,让每一个点都试着担任中间点去去找最短路,记得初始化自环。广播模型,就是找到所有最短路中最大值,
#include<bits/stdc++.h>
using namespace std;
const int N = 110, INF = 0x3f3f3f3f;
int dist[N][N];
int n, m;
int main()
{
cin>>n>>m;
memset(dist, 0x3f, sizeof dist);
for(int i = 0; i <= n; i ++ ) dist[i][i] = 0; //记得初始化自环
for(int i = 0; i < m; i ++ ){
int a, b, c;
cin>>a>>b>>c;
dist[a][b] = dist[b][a] = min(c, dist[a][b]);
}
//floyd是以每一个点都当成中间点尝试找到最短路,所以中间点在最外层循环
for(int k = 1; k <= n; k ++ ){
for(int i = 1; i <= n; i ++ ){
for(int j = 1; j <= n; j ++ ){
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
int res = 0;
for(int i = 1; i <= n; i ++ ){
if(dist[1][i] == INF){
res = -1;
break;
}
res = max(res, dist[1][i]);
}
cout<<res<<endl;
return 0;
}
边栏推荐
- AcWing 1137. 选择最佳线路 题解(最短路)
- Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
- Reading notes of code neatness
- MySQL高级(进阶)SQL语句
- Getting started with typescript
- 思考变量引起的巨大变化
- Mobile robot path planning: artificial potential field method [easy to understand]
- Notes de lecture sur le code propre
- How performance testing creates business value
- 《架构整洁之道》读书笔记(下)
猜你喜欢
Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others
Thread application instance
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Yolov3 trains its own data set to generate train txt
What is 9D movie like? (+ common sense of dimension space)
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
《重构:改善既有代码的设计》读书笔记(上)
随机推荐
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
Imitation Jingdong magnifying glass effect (pink teacher version)
Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others
AcWing 1129. 热浪 题解(最短路—spfa)
Reading notes of code neatness
PHP asymmetric encryption method private key and public key encryption and decryption method
搭建主从模式集群redis
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
Excel finds the same value in a column, deletes the row or replaces it with a blank value
注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
A4988 drive stepper motor "recommended collection"
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
What is the MySQL backup suffix_ MySQL backup restore
安装单机redis详细教程
MySQL
数据降维——主成分分析
Gamefi链游系统开发(NFT链游开发功能)丨NFT链游系统开发(Gamefi链游开发源码)
开发固定资产管理系统,开发固定资产管理系统用什么语音
C file input operation