当前位置:网站首页>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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
- [C language] convert decimal numbers to binary numbers
- Drools dynamically add, modify, and delete rules
- 堆(优先级队列)
- mysql表的增删改查(进阶)
- Tas (file d'attente prioritaire)
- 浏览器node事件循环
- [old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
- Drools terminates the execution of other rules after executing one rule
- JSON序列化 与 解析
猜你喜欢

BOM DOM

WSL 2 will not be installed yet? It's enough to read this article

Writing method of then part in drools
![1380. Lucky numbers in the matrix [two-dimensional array, matrix]](/img/8c/c050af5672268bc7e0df3250f7ff1d.jpg)
1380. Lucky numbers in the matrix [two-dimensional array, matrix]

Deep understanding of P-R curve, ROC and AUC

AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning

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

Find the common ancestor of any two numbers in a binary tree

堆(优先级队列)

初始JDBC 编程
随机推荐
CDH6之Sqoop添加数据库驱动
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
Enhance network security of kubernetes with cilium
Brush questions --- binary tree --2
Calculate the maximum path sum of binary tree
Drools executes the specified rule
Addition, deletion, modification and query of MySQL table (Advanced)
post请求体内容无法重复获取
Experiment of connecting mobile phone hotspot based on Arduino and esp8266 (successful)
ThreadLocal的简单理解
记录一下MySql update会锁定哪些范围的数据
mysql索引和事务
China traffic sign detection data set
Docker-compose配置Mysql,Redis,MongoDB
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
MySQL and PostgreSQL methods to grab slow SQL
Intel 内部指令 --- AVX和AVX2学习笔记
趣味 面试题
刷题---二叉树--2
LeetCode—剑指 Offer 37、38