当前位置:网站首页>AcWing 1128. Messenger solution (shortest path Floyd)
AcWing 1128. Messenger solution (shortest path Floyd)
2022-07-02 19:39:00 【Mr. Qiao Da】
AcWing 1128. messenger
floyd Find the shortest path , Triple cycle , Let every point try to act as the middle point to find the shortest path , Remember to initialize the self ring . Broadcast model , Is to find the maximum value of all the shortest paths ,
#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; // Remember to initialize the self ring
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 Every point is regarded as the middle point to try to find the shortest path , So the middle point circulates in the outermost layer
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;
}
边栏推荐
- SQLite 3.39.0 发布,支持右外连接和全外连接
- 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
- Watchful pioneer world outlook Architecture - (how does a good game come from)
- 良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
- Implementation of 453 ATOI function
- 开始练习书法
- 《MongoDB入门教程》第03篇 MongoDB基本概念
- 程序猿入门攻略(十二)——数据的存储
- Npoi export Excel2007
- 职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
猜你喜欢
Istio1.12:安装和快速入门
定了,就是它!
PHP parser badminton reservation applet development requires online system
字典
MySQL function
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
《重构:改善既有代码的设计》读书笔记(下)
良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
Introduction to program ape (XII) -- data storage
随机推荐
2022.7.1-----leetcode. two hundred and forty-one
《架构整洁之道》读书笔记(下)
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
KT148A语音芯片ic的硬件设计注意事项
Introduction to mongodb chapter 03 basic concepts of mongodb
开始练习书法
zabbix5客户端安装和配置
Golang concurrent programming goroutine, channel, sync
Juypter notebook modify the default open folder and default browser
450-深信服面经1
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
从20s优化到500ms,我用了这三招
R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线(indifference curve)
Implementation of 453 ATOI function
使用IDM下载百度网盘的文件(亲测有用)[通俗易懂]
Istio部署:快速上手微服务,
How to print mybats log plug-in using XML file
多态的理解以及作用
AcWing 1135. 新年好 题解(最短路+搜索)
End to end object detection with transformers (Detr) paper reading and understanding