当前位置:网站首页>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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Input a three digit number and output its single digit, ten digit and hundred digit.
- 初始JDBC 编程
- Drools terminates the execution of other rules after executing one rule
- Go learning notes - multithreading
- Deep copy event bus
- [C language] convert decimal numbers to binary numbers
- (C language) octal conversion decimal
- Docker-compose配置Mysql,Redis,MongoDB
- Map and set
- arcgis js 4. Add pictures to x map
猜你喜欢
刷题---二叉树--2
记录一下MySql update会锁定哪些范围的数据
【工控老马】西门子PLC Siemens PLC TCP协议详解
模块化 CommonJS ES Module
[C language] convert decimal numbers to binary numbers
The blink code based on Arduino and esp8266 runs successfully (including error analysis)
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
CDA数据分析——AARRR增长模型的介绍、使用
BOM DOM
Bom Dom
随机推荐
(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
mysql索引和事务
Drools executes string rules or executes a rule file
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
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
Deep copy event bus
深拷貝 事件總線
Adding database driver to sqoop of cdh6
CDA data analysis -- Introduction and use of aarrr growth model
线性DP AcWing 899. 编辑距离
MySQL indexes and transactions
Heap (priority queue)
SparkContext: Error initializing SparkContext解决方法
Multiply LCA (nearest common ancestor)
Map and set
Drools dynamically add, modify, and delete rules
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Maximum profit of jz63 shares
Intel internal instructions - AVX and avx2 learning notes
Leetcode - Sword finger offer 59 - I, 59 - II