当前位置:网站首页>【最短路】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);
}
}
边栏推荐
- 大佬们有没有人遇到过 flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取
- 本地navicat连接liunx下的oracle报权限不足
- MIF file format record
- Input type= "password" how to solve the problem of password automatically brought in
- STM32入门开发 NEC红外线协议解码(超低成本无线传输方案)
- Electron adding SQLite database
- Use metersphere to keep your testing work efficient
- audit 移植
- Use references
- 关于测试人生的一站式发展建议
猜你喜欢
千人规模互联网公司研发效能成功之路
Activity生命周期
sql里,我想设置外键,为什么出现这个问题
Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
测试优惠券要怎么写测试用例?
Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]
JS add spaces to the string
How to add aplayer music player in blog
科普达人丨一文弄懂什么是云计算?
技术分享 | 抓包分析 TCP 协议
随机推荐
学习笔记|数据小白使用DataEase制作数据大屏
Briefly introduce closures and some application scenarios
正在運行的Kubernetes集群想要調整Pod的網段地址
R language uses image of magick package_ Mosaic functions and images_ The flatten function stacks multiple pictures together to form a stack layers on top of each other
Onedns helps college industry network security
关于SIoU《SIoU Loss: More Powerful Learning for Bounding Box Regression Zhora Gevorgyan 》的一些看法及代码实现
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
The running kubernetes cluster wants to adjust the network segment address of pod
Activity生命周期
MIF file format record
Activity lifecycle
STM32 entry development NEC infrared protocol decoding (ultra low cost wireless transmission scheme)
Qt|多个窗口共有一个提示框类
基于Retrofit框架的金山API翻译功能案例
sql里,我想设置外键,为什么出现这个问题
Test the foundation of development, and teach you to prepare for a fully functional web platform environment
How to write test cases for test coupons?
What is cloud computing?
基于华为云IOT设计智能称重系统(STM32)
Web端自动化测试失败的原因