当前位置:网站首页>[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 性能提升
- SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
- [system design] index monitoring and alarm system
- Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
- LeetCode - 面试题17.24 最大子矩阵
- 正在运行的Kubernetes集群想要调整Pod的网段地址
- 通过环境变量将 Pod 信息呈现给容器
- When sink is consumed in mysql, the self incrementing primary key has been set in the database table. How to operate in Flink?
- 【时间格式工具函数的封装】
- Flet教程之 17 Card卡片组件 基础入门(教程含源码)
猜你喜欢

SwiftUI 教程之如何在 2 秒内实现自动滚动功能

Suggestions on one-stop development of testing life

Learning notes | data Xiaobai uses dataease to make a large data screen

How to write test cases for test coupons?
![Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]](/img/ed/29d6bf21f857ec925bf425ad594e36.png)
Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]

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

Unsupervised learning of visual features by contracting cluster assignments

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

Onedns helps college industry network security

Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
随机推荐
Internet Protocol
SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
对比学习之 Unsupervised Learning of Visual Features by Contrasting Cluster Assignments
请查收.NET MAUI 的最新学习资源
The running kubernetes cluster wants to adjust the network segment address of pod
Easyui学习整理笔记
What development models did you know during the interview? Just read this one
深度学习秋招面试题集锦(一)
[encapsulation of time format tool functions]
R语言可视化分面图、假设检验、多变量分组t检验、可视化多变量分组分面箱图(faceting boxplot)并添加显著性水平、添加抖动数据点(jitter points)
electron 添加 SQLite 数据库
In my limited software testing experience, a full-time summary of automation testing experience
聊聊SOC启动(七) uboot启动流程三
[question] Compilation Principle
【愚公系列】2022年7月 Go教学课程 005-变量
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
Audit migration
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
Design intelligent weighing system based on Huawei cloud IOT (STM32)
0.96 inch IIC LCD driver based on stc8g1k08