当前位置:网站首页>[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);
}
}
边栏推荐
- What development models did you know during the interview? Just read this one
- 【纹理特征提取】基于matlab局部二值模式LBP图像纹理特征提取【含Matlab源码 1931期】
- How to add aplayer music player in blog
- 聊聊SOC启动(七) uboot启动流程三
- Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift
- STM32 entry development NEC infrared protocol decoding (ultra low cost wireless transmission scheme)
- Talk about SOC startup (11) kernel initialization
- 大佬们有没有人遇到过 flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取
- Android 面试知识点
- [encapsulation of time format tool functions]
猜你喜欢
Design intelligent weighing system based on Huawei cloud IOT (STM32)
electron添加SQLite数据库
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
技术分享 | 抓包分析 TCP 协议
Le Cluster kubernets en cours d'exécution veut ajuster l'adresse du segment réseau du pod
【滤波跟踪】基于matlab扩展卡尔曼滤波EKF和无迹卡尔曼滤波UKF比较【含Matlab源码 1933期】
Cmu15445 (fall 2019) project 2 - hash table details
. Net Maui performance improvement
Electron adding SQLite database
随机推荐
深度学习秋招面试题集锦(一)
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
In depth learning autumn recruitment interview questions collection (1)
Talk about SOC startup (VI) uboot startup process II
VIM command mode and input mode switching
R language uses the quantile function to calculate the quantile of the score value (20%, 40%, 60%, 80%), uses the logical operator to encode the corresponding quantile interval (quantile) into the cla
Onedns helps college industry network security
sink 消费 到 MySQL, 数据库表里面已经设置了 自增主键, flink 里面,如何 操作?
聊聊SOC启动(十) 内核启动先导知识
How much do you know about excel formula?
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
清华姚班程序员,网上征婚被骂?
自律,提升自制力原来也有方法
正在运行的Kubernetes集群想要调整Pod的网段地址
Poor math students who once dropped out of school won the fields award this year
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
《论文阅读》Neural Approaches to Conversational AI(1)
Easyui学习整理笔记
【纹理特征提取】基于matlab局部二值模式LBP图像纹理特征提取【含Matlab源码 1931期】