当前位置:网站首页>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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
- Introduction to CPU instruction set
- Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
- Drools dynamically add, modify, and delete rules
- The blink code based on Arduino and esp8266 runs successfully (including error analysis)
- lombok常用注解
- High performance erasure code coding
- (C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
- MySQL与PostgreSQL抓取慢sql的方法
猜你喜欢

Deep copy event bus

Brush questions --- binary tree --2

arcgis js 4.x 地图中加入图片

【工控老马】西门子PLC Siemens PLC TCP协议详解

Deep understanding of P-R curve, ROC and AUC
![2.6 using recursion and stack - [tower of Hanoi problem]](/img/fc/45038170dafd104691c93716b103cf.jpg)
2.6 using recursion and stack - [tower of Hanoi problem]
![[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol](/img/13/9002244555ebe8a61660c2506993fa.png)
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol

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

mysql数据库基础

堆(优先级队列)
随机推荐
甜心教主:王心凌
Sse/avx instruction set and API of SIMD
2.6 using recursion and stack - [tower of Hanoi problem]
SparkContext: Error initializing SparkContext解决方法
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
WSL 2 will not be installed yet? It's enough to read this article
arcgis js 4. Add pictures to x map
Shutter encapsulated button
刷题---二叉树--2
(C language) octal conversion decimal
mysql数据库基础
【工控老马】西门子PLC Siemens PLC TCP协议详解
计数类DP AcWing 900. 整数划分
Leetcode - Sword finger offer 37, 38
IPhone 6 plus is listed in Apple's "retro products" list
LeetCode—剑指 Offer 37、38
Sparkcontext: error initializing sparkcontext solution
Mysql database foundation
堆(優先級隊列)
drools决策表的简单使用