当前位置:网站首页>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;
}
边栏推荐
- AcWing 1134. 最短路计数 题解(最短路)
- Postman下载安装
- Pytorch版本、CUDA版本与显卡驱动版本的对应关系
- SQLite 3.39.0 发布,支持右外连接和全外连接
- golang:[]byte转string
- SIFT feature point extraction "suggestions collection"
- Bubble sort array
- VBScript详解(一)
- Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
- [error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
猜你喜欢

IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config

定了,就是它!

Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode

Usage of ieda refactor

MySQL function

AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)

ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
Bubble sort array

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

Data dimensionality reduction principal component analysis
随机推荐
Use cheat engine to modify money, life and stars in Kingdom rush
mysql函数
[pytorch learning notes] tensor
AcWing 342. 道路与航线 题解 (最短路、拓扑排序)
AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
pxe装机「建议收藏」
Golang:[]byte to string
Understanding and function of polymorphism
SQLite 3.39.0 发布,支持右外连接和全外连接
简书自动阅读
Mobile robot path planning: artificial potential field method [easy to understand]
AcWing 342. Road and route problem solving (shortest path, topological sorting)
Chapter 7 - class foundation
Qpropertyanimation use and toast case list in QT
Thread application instance
[ERP software] what are the dangers of the secondary development of ERP system?
Which video recording software is better for the computer
AcWing 1126. 最小花费 题解(最短路—dijkstra)
Implementation of 452 strcpy, strcat, StrCmp, strstr, strchr
Infix expression is converted to suffix expression (C language code + detailed explanation)