当前位置:网站首页>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;
}
边栏推荐
- Introduction of Ethernet PHY layer chip lan8720a
- AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
- Istio部署:快速上手微服务,
- 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
- Think about the huge changes caused by variables
- 解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
- AcWing 1125. 牛的旅行 题解(最短路、直径)
- IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
- golang:[]byte转string
- AcWing 1131. Saving Private Ryan (the shortest way)
猜你喜欢

Yes, that's it!

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

《重构:改善既有代码的设计》读书笔记(上)

450 Shenxin Mianjing 1

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

SQLite 3.39.0 release supports right external connection and all external connection

Introduction to program ape (XII) -- data storage
Bubble sort array

Data dimensionality reduction factor analysis

Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
随机推荐
MySQL table historical data cleaning summary
Codeworks round 802 (Div. 2) pure supplementary questions
Mobile robot path planning: artificial potential field method [easy to understand]
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
Usage of ieda refactor
4274. Suffix expression - binary expression tree
Build a master-slave mode cluster redis
LeetCode 0871. Minimum refueling times - similar to poj2431 jungle adventure
Bubble sort array
职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
Watchful pioneer world outlook Architecture - (how does a good game come from)
Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
Detailed tutorial on installing stand-alone redis
VBScript详解(一)
AcWing 1125. Cattle travel problem solution (shortest path, diameter)
Refactoring: improving the design of existing code (Part 1)
[ERP software] what are the dangers of the secondary development of ERP system?
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
Introduction of Ethernet PHY layer chip lan8720a