Floyd求最短路

#include <bits/stdc++.h> using namespace std; const int N = 205; int d[N][N]; int n, m, q; int INF = 1e9; void floyd() {     for (int k = 1; k <= n; ++k) {         for (int i = 1; i <= n; ++i) {             for (int j = 1; j <= n; ++j) {                 d[i][j] = min(d[i][j], d[i][k] + d[k][j]);             }         }     } }; int main() {          cin >> n >> m >> q;     for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {             if (i == j) {                 d[i][j] = 0;             } else {                 d[i][j] = INF;             }         }     }          while (m--) {         int x, y, z;         scanf("%d%d%d", &x, &y, &z);         d[x][y] = min(d[x][y], z);     }          floyd();          while (q--) {         int x, y;         scanf("%d%d", &x, &y);         if (d[x][y] > INF / 2) {             puts("impossible");         } else {             printf("%dn", d[x][y]);         }     }     return 0; }
Floyd求最短路leetcode刷题题解部分资料来自网络,侵权毕设源码联系删除

区块链毕设网(www.qklbishe.com)全网最靠谱的原创区块链毕设代做网站
部分资料来自网络,侵权联系删除!
资源收费仅为搬运整理打赏费用,用户自愿支付 !
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台 » Floyd求最短路leetcode刷题题解