当前位置:网站首页>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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Drools dynamically add, modify, and delete rules
- WSL 2 will not be installed yet? It's enough to read this article
- LeetCode—剑指 Offer 59 - I、59 - II
- Shuttle encapsulated AppBar
- There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
- China traffic sign detection data set
- Go学习笔记—基于Go的进程间通信
- 区间DP AcWing 282. 石子合并
- Input a three digit number and output its single digit, ten digit and hundred digit.
- kubenetes中port、targetPort、nodePort、containerPort的区别与联系
猜你喜欢

mysql数据库基础

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

浏览器node事件循环

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

防抖 节流

drools中then部分的写法

(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.

堆(優先級隊列)

计数类DP AcWing 900. 整数划分

drools动态增加、修改、删除规则
随机推荐
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
Simple understanding of ThreadLocal
In development, why do you find someone who is paid more than you but doesn't write any code?
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
Distributed machine learning framework and high-dimensional real-time recommendation system
Jenkins voucher management
Drools executes string rules or executes a rule file
Sort---
使用Sqoop把ADS层数据导出到MySQL
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
Map and set
[C language] Yang Hui triangle, customize the number of lines of the triangle
Shutter encapsulated button
线性DP AcWing 902. 最短编辑距离
Writing method of then part in drools
Anti shake throttle
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
Maximum profit of jz63 shares
MySQL与PostgreSQL抓取慢sql的方法
Deep copy event bus