当前位置:网站首页>Floyd AcWing 854. Floyd求最短路
Floyd AcWing 854. Floyd求最短路
2022-07-02 09:43:00 【T_Y_F666】
Floyd AcWing 854. Floyd求最短路
原题链接
算法标签
最短路 Floyd
思路

代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 205, INF = 0x3f3f3f3f;
int d[N][N];
int n,m,k;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
void fl(){
rep(k, 1, n+1){
rep(i, 1, n+1){
rep(j, 1, n+1){
d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read(), m=read(), k=read();
rep(i, 1, n+1){
rep(j, 1, n+1){
if(i-j){
d[i][j]=INF;
}else{
d[i][j]=0;
}
}
}
while(m--){
int x=read(), y=read(), z=read();
d[x][y]=min(d[x][y], z);
}
fl();
while(k--){
int x=read(), y=read();
if(d[x][y]>INF/2){
puts("impossible");
}else{
printf("%lld\n", d[x][y]);
}
}
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- (C language) octal conversion decimal
- LeetCode—剑指 Offer 51. 数组中的逆序对
- Lekao: 22 year first-class fire engineer "technical practice" knowledge points
- There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
- FastDateFormat为什么线程安全
- Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
- Drools terminates the execution of other rules after executing one rule
- 刷题---二叉树--2
- BOM DOM
- 上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
猜你喜欢

mysql数据库基础

Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer

Performance tuning project case

Docker-compose配置Mysql,Redis,MongoDB

Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime

kubenetes中port、targetPort、nodePort、containerPort的区别与联系
![[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol](/img/13/9002244555ebe8a61660c2506993fa.png)
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol

防抖 节流

Multiply LCA (nearest common ancestor)

mysql表的增删改查(进阶)
随机推荐
Shutter encapsulated button
MySQL and PostgreSQL methods to grab slow SQL
When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
线性DP AcWing 897. 最长公共子序列
计算二叉树的最大路径和
drools执行完某个规则后终止别的规则执行
SparkContext: Error initializing SparkContext解决方法
Post request body content cannot be retrieved repeatedly
Intel 内部指令 --- AVX和AVX2学习笔记
深拷贝 事件总线
AI mid stage technology research
BOM DOM
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
Differences between nodes and sharding in ES cluster
Introduction to CPU instruction set
包管理工具
排序---
In development, why do you find someone who is paid more than you but doesn't write any code?