当前位置:网站首页>[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
2022-07-07 11:46:00 【Twilight_ years】

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);
}
}边栏推荐
- . Net Maui performance improvement
- 浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
- Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
- Flet教程之 17 Card卡片组件 基础入门(教程含源码)
- VIM command mode and input mode switching
- Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
- 博客搬家到知乎
- Flet教程之 15 GridView 基础入门(教程含源码)
- 千人規模互聯網公司研發效能成功之路
- 千人规模互联网公司研发效能成功之路
猜你喜欢

Test the foundation of development, and teach you to prepare for a fully functional web platform environment

How much do you know about excel formula?

本地navicat连接liunx下的oracle报权限不足

Design intelligent weighing system based on Huawei cloud IOT (STM32)

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

Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist

【最短路】Acwing1128信使:floyd最短路

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

一度辍学的数学差生,获得今年菲尔兹奖

总结了200道经典的机器学习面试题(附参考答案)
随机推荐
STM32 entry development write DS18B20 temperature sensor driver (read ambient temperature, support cascade)
Automated testing framework
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
使用MeterSphere让你的测试工作持续高效
How much do you know about excel formula?
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
千人规模互联网公司研发效能成功之路
Two week selection of tdengine community issues | phase II
[encapsulation of time format tool functions]
竟然有一半的人不知道 for 与 foreach 的区别???
VIM command mode and input mode switching
QT | multiple windows share a prompt box class
What development models did you know during the interview? Just read this one
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?
深度学习秋招面试题集锦(一)
Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift
正在运行的Kubernetes集群想要调整Pod的网段地址
Flet教程之 14 ListTile 基础入门(教程含源码)
正在運行的Kubernetes集群想要調整Pod的網段地址
【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)