当前位置:网站首页>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;
}
边栏推荐
- QT中的QPropertyAnimation使用和toast案列
- Emmet基础语法
- 4274. 后缀表达式-二叉表达式树
- Markdown基础语法
- 《代碼整潔之道》讀書筆記
- Talk about the design of red envelope activities in e-commerce system
- Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
- A4988 drive stepper motor "recommended collection"
- According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
- 教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
猜你喜欢
![[test development] software testing - concept](/img/24/9ee885d46f7200ae7449957ca96b9d.png)
[test development] software testing - concept

xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

450-深信服面经1

IEDA refactor的用法

Data dimensionality reduction principal component analysis

What is 9D movie like? (+ common sense of dimension space)

Processing strategy of message queue message loss and repeated message sending

数据降维——主成分分析

PyTorch函数中的__call__和forward函数

《重构:改善既有代码的设计》读书笔记(上)
随机推荐
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
Refactoring: improving the design of existing code (Part 1)
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
【ERP软件】ERP体系二次开发有哪些危险?
According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
Codeforces Round #802 (Div. 2) 纯补题
Use cheat engine to modify money, life and stars in Kingdom rush
Fastdfs installation
潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
Horizontal ultra vires and vertical ultra vires [easy to understand]
Golang concurrent programming goroutine, channel, sync
A4988驱动步进电机「建议收藏」
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
2022 compilation principle final examination recall Edition
开发固定资产管理系统,开发固定资产管理系统用什么语音
ORA-01455: converting column overflows integer datatype
预处理和预处理宏
2022.7.1-----leetcode.241
451-memcpy、memmove、memset的实现