当前位置:网站首页>[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);
}
}边栏推荐
- Case study of Jinshan API translation function based on retrofit framework
- 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
- 使用MeterSphere让你的测试工作持续高效
- Reasons for the failure of web side automation test
- 一起探索云服务之云数据库
- R語言使用magick包的image_mosaic函數和image_flatten函數把多張圖片堆疊在一起形成堆疊組合圖像(Stack layers on top of each other)
- 大佬们有没有人遇到过 flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取
- EasyUI learn to organize notes
- La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
- The running kubernetes cluster wants to adjust the network segment address of pod
猜你喜欢

Table replication in PostgreSQL

Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan

Poor math students who once dropped out of school won the fields award this year

What is cloud computing?

聊聊SOC启动(十一) 内核初始化

La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
![Verilog design responder [with source code]](/img/91/6359a2f3fa0045b4a88956a475488c.png)
Verilog design responder [with source code]

.NET MAUI 性能提升

Distributed database master-slave configuration (MySQL)

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?
随机推荐
聊聊SOC启动(七) uboot启动流程三
R語言使用magick包的image_mosaic函數和image_flatten函數把多張圖片堆疊在一起形成堆疊組合圖像(Stack layers on top of each other)
问下flinkcdc2.2.0的版本,支持并发,这个并发是指多并行度吗,现在发现,mysqlcdc全
About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection
深度学习秋招面试题集锦(一)
Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
Apprentissage comparatif non supervisé des caractéristiques visuelles par les assignations de groupes de contrôle
Cmu15445 (fall 2019) project 2 - hash table details
Reasons for the failure of web side automation test
Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
對比學習之 Unsupervised Learning of Visual Features by Contrasting Cluster Assignments
QT | multiple windows share a prompt box class
OneDNS助力高校行业网络安全
Creative information was surveyed by 2 institutions: greatdb database has been deployed in 9 places
[question] Compilation Principle
Use metersphere to keep your testing work efficient
总结了200道经典的机器学习面试题(附参考答案)
Complete collection of common error handling in MySQL installation
超标量处理器设计 姚永斌 第9章 指令执行 摘录
SwiftUI 教程之如何在 2 秒内实现自动滚动功能