当前位置:网站首页>[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);
}
}
边栏推荐
- 清华姚班程序员,网上征婚被骂?
- 本地navicat连接liunx下的oracle报权限不足
- Distributed database master-slave configuration (MySQL)
- 千人規模互聯網公司研發效能成功之路
- 聊聊SOC启动(十一) 内核初始化
- Solve the problem that vscode can only open two tabs
- [system design] index monitoring and alarm system
- Poor math students who once dropped out of school won the fields award this year
- Talk about SOC startup (11) kernel initialization
- Case study of Jinshan API translation function based on retrofit framework
猜你喜欢
超标量处理器设计 姚永斌 第10章 指令提交 摘录
千人規模互聯網公司研發效能成功之路
The running kubernetes cluster wants to adjust the network segment address of pod
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
聊聊SOC启动(十) 内核启动先导知识
Table replication in PostgreSQL
相机标定(2): 单目相机标定总结
Excel公式知多少?
In my limited software testing experience, a full-time summary of automation testing experience
随机推荐
TDengine 社区问题双周精选 | 第二期
Tsinghua Yaoban programmers, online marriage was scolded?
深度学习秋招面试题集锦(一)
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting boxplot, and add significance levels and jitter points
禁锢自己的因素,原来有这么多
基于华为云IOT设计智能称重系统(STM32)
Talk about SOC startup (11) kernel initialization
Onedns helps college industry network security
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)
Neural approvals to conversational AI (1)
Talk about SOC startup (VI) uboot startup process II
Two week selection of tdengine community issues | phase II
STM32入门开发 采用IIC硬件时序读写AT24C08(EEPROM)
Briefly introduce closures and some application scenarios
QT | multiple windows share a prompt box class
Talk about SOC startup (x) kernel startup pilot knowledge
Android interview knowledge points
Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
Leetcode - interview question 17.24 maximum submatrix