当前位置:网站首页>【最短路】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);
}
}边栏推荐
- STM32 entry development uses IIC hardware timing to read and write AT24C08 (EEPROM)
- Design intelligent weighing system based on Huawei cloud IOT (STM32)
- Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
- 技术分享 | 抓包分析 TCP 协议
- The database synchronization tool dbsync adds support for mongodb and es
- Audit migration
- The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
- 聊聊SOC启动(十) 内核启动先导知识
- About the application of writing shell script JSON in JMeter
- Talk about SOC startup (VI) uboot startup process II
猜你喜欢

学习笔记|数据小白使用DataEase制作数据大屏

在我有限的软件测试经历里,一段专职的自动化测试经验总结

对比学习之 Unsupervised Learning of Visual Features by Contrasting Cluster Assignments

Talk about SOC startup (11) kernel initialization

Debezium同步之Debezium架构详解

如何在博客中添加Aplayer音乐播放器

禁锢自己的因素,原来有这么多

Avoid mutating a prop directly since the value will be overwritten whenever the parent component

The running kubernetes cluster wants to adjust the network segment address of pod

Activity lifecycle
随机推荐
千人规模互联网公司研发效能成功之路
vim 的各种用法,很实用哦,都是本人是在工作中学习和总结的
R Language Using Image of magick package Mosaic Function and Image La fonction flatten empile plusieurs images ensemble pour former des couches empilées sur chaque autre
QT implements the delete method of the container
How to remove addition and subtraction from inputnumber input box
面试被问到了解哪些开发模型?看这一篇就够了
What is cloud computing?
CentOS系统下Redis安装和自启动配置的步骤
oracle常见锁表处理方式
In my limited software testing experience, a full-time summary of automation testing experience
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
Talk about SOC startup (IX) adding a new board to uboot
Le Cluster kubernets en cours d'exécution veut ajuster l'adresse du segment réseau du pod
自律,提升自制力原来也有方法
【愚公系列】2022年7月 Go教学课程 005-变量
通过 Play Integrity API 的 nonce 字段提高应用安全性
核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
Use metersphere to keep your testing work efficient
OneDNS助力高校行业网络安全