当前位置:网站首页>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;
}
边栏推荐
- SIFT特征点提取「建议收藏」
- Reading notes of code neatness
- Golang concurrent programming goroutine, channel, sync
- Processing strategy of message queue message loss and repeated message sending
- 2022 compilation principle final examination recall Edition
- 电脑使用哪个录制视频软件比较好
- Gmapping code analysis [easy to understand]
- 《架构整洁之道》读书笔记(下)
- Quanzhi A33 uses mainline u-boot
- metric_ Logger urination
猜你喜欢
数据降维——因子分析
Quanzhi A33 uses mainline u-boot
Data dimensionality reduction principal component analysis
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Novice must see, click two buttons to switch to different content
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
安装单机redis详细教程
[test development] software testing - concept
随机推荐
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Quanzhi A33 uses mainline u-boot
A4988 drive stepper motor "recommended collection"
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
【ERP软件】ERP体系二次开发有哪些危险?
AcWing 1134. 最短路计数 题解(最短路)
What is 9D movie like? (+ common sense of dimension space)
数据降维——因子分析
Introduction of Ethernet PHY layer chip lan8720a
2022.7.1-----leetcode. two hundred and forty-one
MySQL advanced (Advanced) SQL statement
C file input operation
Markdown基础语法
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
ICDE 2023|TKDE Poster Session(CFP)
思考变量引起的巨大变化
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
Use cheat engine to modify money, life and stars in Kingdom rush
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5