当前位置:网站首页>【最短路】Acwing1128信使:floyd最短路
【最短路】Acwing1128信使:floyd最短路
2022-07-07 09:46:00 【暮色_年华】

import java.io.*;
import java.util.*;
class Main{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static final int N=1000;
static final int INF=(int)1e8;
static int[][] dist=new int[N][N];
static int n,m;
public static void main(String[]args)throws IOException{
String[] s=br.readLine().split(" ");
n=Integer.parseInt(s[0]);
m=Integer.parseInt(s[1]);
for(int i=1;i<=n;i++)
Arrays.fill(dist[i],INF);
for(int i=1;i<=n;i++){
dist[i][i]=0;
}
for(int i=0;i<m;i++){
s=br.readLine().split(" ");
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
int c=Integer.parseInt(s[2]);
dist[a][b]=dist[b][a]=Math.min(dist[a][b],c);
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j]=Math.min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}
int res=0;
for(int i=1;i<=n;i++){
res=Math.max(dist[1][i],res);
}
if(res>INF/2)System.out.println(-1);
else System.out.println(res);
}
}边栏推荐
- 测试开发基础,教你做一个完整功能的Web平台之环境准备
- Test the foundation of development, and teach you to prepare for a fully functional web platform environment
- Talk about SOC startup (VII) uboot startup process III
- TDengine 社区问题双周精选 | 第二期
- 科普达人丨一文弄懂什么是云计算?
- .NET MAUI 性能提升
- 什么是高内聚、低耦合?
- 自律,提升自制力原来也有方法
- 关于SIoU《SIoU Loss: More Powerful Learning for Bounding Box Regression Zhora Gevorgyan 》的一些看法及代码实现
- 问下flinkcdc2.2.0的版本,支持并发,这个并发是指多并行度吗,现在发现,mysqlcdc全
猜你喜欢

.NET MAUI 性能提升

Using ENSP to do MPLS pseudo wire test

How to use cherry pick?

Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan

Enclosed please find. Net Maui's latest learning resources

浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派

What development models did you know during the interview? Just read this one

通过 Play Integrity API 的 nonce 字段提高应用安全性

Talk about SOC startup (IX) adding a new board to uboot

RationalDMIS2022阵列工件测量
随机推荐
学习笔记|数据小白使用DataEase制作数据大屏
高考作文,高频提及科技那些事儿……
audit 移植
LeetCode - 面试题17.24 最大子矩阵
相机标定(2): 单目相机标定总结
分布式数据库主从配置(MySQL)
Solve the problem that vscode can only open two tabs
Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan
The database synchronization tool dbsync adds support for mongodb and es
electron 添加 SQLite 数据库
V-for img SRC rendering fails
oracle常见锁表处理方式
Poor math students who once dropped out of school won the fields award this year
What is cloud computing?
使用引用
Qt|多个窗口共有一个提示框类
‘module‘ object is not callable错误
禁锢自己的因素,原来有这么多
Reasons for the failure of web side automation test
《论文阅读》Neural Approaches to Conversational AI(1)