当前位置:网站首页>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 
边栏推荐
- Lekao: 22 year first-class fire engineer "technical practice" knowledge points
- OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
- Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
- AI中台技术调研
- Is the neural network (pinn) with embedded physical knowledge a pit?
- 正确遍历EntryList方法
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
- 线性DP AcWing 898. 数字三角形
- bellman-ford AcWing 853. 有边数限制的最短路
猜你喜欢
![[FFH] little bear driver calling process (take calling LED light driver as an example)](/img/e7/153ae9f1befc12825d277620049f9d.jpg)
[FFH] little bear driver calling process (take calling LED light driver as an example)

Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)

高性能纠删码编码

3 A VTT端接 稳压器 NCP51200MNTXG资料

Heap acwing 838 Heap sort

模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计

Deep copy event bus

High performance erasure code coding

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

BOM DOM
随机推荐
[FFH] little bear driver calling process (take calling LED light driver as an example)
Drools executes string rules or executes a rule file
Sparkcontext: error initializing sparkcontext solution
Use MySQL events to regularly perform post seven world line tasks
About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
Embedded Software Engineer career planning
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
spfa AcWing 852. spfa判断负环
Bom Dom
通过反射执行任意类的任意方法
计数类DP AcWing 900. 整数划分
Heap acwing 839 Simulated reactor
一些突然迸发出的程序思想(模块化处理)
C#运算符
Calculate the maximum path sum of binary tree
2.6 using recursion and stack - [tower of Hanoi problem]
High performance erasure code coding
About asp Net MVC project in local vs running response time is too long to access, the solution!