当前位置:网站首页>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;
}
边栏推荐
- Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
- NMF-matlab
- AcWing 383. Sightseeing problem solution (shortest circuit)
- Quanzhi A33 uses mainline u-boot
- AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
- 搭建哨兵模式reids、redis从节点脱离哨兵集群
- Advanced performance test series "24. Execute SQL script through JDBC"
- Is there any security guarantee for the ranking of stock and securities companies
- 451 implementation of memcpy, memmove and memset
- 思考变量引起的巨大变化
猜你喜欢

Istio1.12:安装和快速入门

Istio部署:快速上手微服务,

守望先锋世界观架构 ——(一款好的游戏是怎么来的)

Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly

Build a master-slave mode cluster redis

SQLite 3.39.0 release supports right external connection and all external connection
![[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)](/img/c1/a00425f2e1824a50644c8fbb15fe38.jpg)
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)

450 Shenxin Mianjing 1

Watchful pioneer world outlook Architecture - (how does a good game come from)

定了,就是它!
随机推荐
AcWing 342. Road and route problem solving (shortest path, topological sorting)
《重构:改善既有代码的设计》读书笔记(上)
AcWing 341. 最优贸易 题解 (最短路、dp)
从20s优化到500ms,我用了这三招
AcWing 1131. Saving Private Ryan (the shortest way)
Refactoring: improving the design of existing code (Part 1)
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
Watchful pioneer world outlook Architecture - (how does a good game come from)
Reading notes of "the way to clean structure" (Part 2)
Cuckoo filter
MySQL advanced (Advanced) SQL statement
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
MySQL表历史数据清理总结
What is the MySQL backup suffix_ MySQL backup restore
Reading notes of code neatness
450-深信服面经1
PHP parser badminton reservation applet development requires online system
高并发下如何避免产生重复数据?
《MongoDB入门教程》第03篇 MongoDB基本概念
Bubble sort array