当前位置:网站首页>Floyd AcWing 854. Floyd finds the shortest path
Floyd AcWing 854. Floyd finds the shortest path
2022-07-02 12:43:00 【T_ Y_ F666】
Floyd AcWing 854. Floyd Find the shortest path
Original link
AcWing 854. Floyd Find the shortest path
Algorithm tags
shortest path Floyd
Ideas
Code
#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;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- CPU指令集介绍
- Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
- Go learning notes - go based interprocess communication
- Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
- 应用LNK306GN-TL 转换器、非隔离电源
- Mongodb redis differences
- Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
- JDBC prevent SQL injection problems and solutions [preparedstatement]
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- Writing method of then part in drools
猜你喜欢
In development, why do you find someone who is paid more than you but doesn't write any code?
spfa AcWing 851. spfa求最短路
深拷贝 事件总线
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
模块化 CommonJS ES Module
区间DP AcWing 282. 石子合并
浏览器存储方案
Drools dynamically add, modify, and delete rules
防抖 节流
[ybtoj advanced training guidance] judgment overflow [error]
随机推荐
Anti shake throttle
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
线性DP AcWing 902. 最短编辑距离
AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning
防抖 节流
VLAN experiment
Enhance network security of kubernetes with cilium
Simple understanding of ThreadLocal
Heap acwing 839 Simulated reactor
Redis bloom filter
Find the common ancestor of any two numbers in a binary tree
How to write a pleasing English mathematical paper
Input box assembly of the shutter package
Day12 control flow if switch while do While guessing numbers game
怎样写一篇赏心悦目的英文数学论文
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Calculate the maximum path sum of binary tree
[ybtoj advanced training guidance] judgment overflow [error]
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
Fluent fluent library encapsulation