当前位置:网站首页>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 
边栏推荐
- JSON序列化 与 解析
- China traffic sign detection data set
- 单指令多数据SIMD的SSE/AVX指令集和API
- 模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
- Mongodb redis differences
- js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
- js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
- Drools executes the specified rule
- MySQL and PostgreSQL methods to grab slow SQL
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
猜你喜欢

High performance erasure code coding

Heap acwing 838 Heap sort

This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry

Bom Dom

堆 AcWing 838. 堆排序
![[ybtoj advanced training guide] similar string [string] [simulation]](/img/eb/acfefc7f85018fe9365d13502e2b0a.jpg)
[ybtoj advanced training guide] similar string [string] [simulation]

What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT

Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution

模块化 CommonJS ES Module

Enhance network security of kubernetes with cilium
随机推荐
BOM DOM
Leetcode - Sword finger offer 59 - I, 59 - II
线性DP AcWing 898. 数字三角形
软件测试面试题-2022年大厂面试题合集
Mongodb redis differences
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
Calculate the maximum path sum of binary tree
Execute any method of any class through reflection
C#修饰符
C#运算符
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
线性DP AcWing 896. 最长上升子序列 II
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
[FFH] little bear driver calling process (take calling LED light driver as an example)
Do you know all the interface test interview questions?
CV2 in OpenCV VideoWriter_ Fourcc() function and cv2 Combined use of videowriter() function
高性能纠删码编码
基于STM32的OLED 屏幕驱动
Sse/avx instruction set and API of SIMD
Embedded Software Engineer career planning