当前位置:网站首页>[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);
}
}
边栏推荐
- Verilog design responder [with source code]
- Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
- Excel公式知多少?
- QT | multiple windows share a prompt box class
- Learning notes | data Xiaobai uses dataease to make a large data screen
- La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
- Various uses of vim are very practical. I learned and summarized them in my work
- 超标量处理器设计 姚永斌 第9章 指令执行 摘录
- The Oracle message permission under the local Navicat connection liunx is insufficient
- Talk about SOC startup (VII) uboot startup process III
猜你喜欢
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
请查收.NET MAUI 的最新学习资源
Flet教程之 17 Card卡片组件 基础入门(教程含源码)
.NET MAUI 性能提升
聊聊SOC启动(十) 内核启动先导知识
正在運行的Kubernetes集群想要調整Pod的網段地址
Half of the people don't know the difference between for and foreach???
18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)
超标量处理器设计 姚永斌 第10章 指令提交 摘录
随机推荐
【系统设计】指标监控和告警系统
STM32入门开发 NEC红外线协议解码(超低成本无线传输方案)
清华姚班程序员,网上征婚被骂?
通过环境变量将 Pod 信息呈现给容器
Verilog design responder [with source code]
本地navicat连接liunx下的oracle报权限不足
Briefly introduce closures and some application scenarios
Nuclear boat (I): when "male mothers" come into reality, can the biotechnology revolution liberate women?
STM32F1与STM32CubeIDE编程实例-315M超再生无线遥控模块驱动
禁锢自己的因素,原来有这么多
audit 移植
问下flinkcdc2.2.0的版本,支持并发,这个并发是指多并行度吗,现在发现,mysqlcdc全
Talk about SOC startup (x) kernel startup pilot knowledge
深度学习秋招面试题集锦(一)
When sink is consumed in mysql, the self incrementing primary key has been set in the database table. How to operate in Flink?
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Vuthink proper installation process
R语言使用magick包的image_mosaic函数和image_flatten函数把多张图片堆叠在一起形成堆叠组合图像(Stack layers on top of each other)
一度辍学的数学差生,获得今年菲尔兹奖
Enclosed please find. Net Maui's latest learning resources