当前位置:网站首页>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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- [FFH] little bear driver calling process (take calling LED light driver as an example)
- Input a three digit number and output its single digit, ten digit and hundred digit.
- Leetcode739 daily temperature
- arcgis js 4.x 地图中加入图片
- MySQL indexes and transactions
- 高性能纠删码编码
- 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
- 计算二叉树的最大路径和
- drools执行完某个规则后终止别的规则执行
- MySQL与PostgreSQL抓取慢sql的方法
猜你喜欢
随机推荐
Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
LeetCode—剑指 Offer 51. 数组中的逆序对
LeetCode—剑指 Offer 59 - I、59 - II
Drools executes the specified rule
Tas (file d'attente prioritaire)
模块化 CommonJS ES Module
Drools terminates the execution of other rules after executing one rule
drools执行指定的规则
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
MySQL与PostgreSQL抓取慢sql的方法
Post request body content cannot be retrieved repeatedly
Map和Set
Embedded Software Engineer career planning
Full link voltage measurement
LeetCode—<动态规划专项>剑指 Offer 19、49、60
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
arcgis js 4.x 地图中加入图片
Multiply LCA (nearest common ancestor)
post请求体内容无法重复获取








