日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

50: Luogu P4568 分层图

發布時間:2023/12/2 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 50: Luogu P4568 分层图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

分層圖最短路模板

#include <iostream> #include <cstdio> #include <cstdlib> #include <ctime> #include <queue> #include <cstring>using namespace std;const int M = 2e6 + 5e5 + 10;#define gc getchar() inline int read() {int x = 0, f = 1; char c = gc;while(c < '0' || c > '9') {if(c == '-') f = -1; c = gc;}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;return x * f; }int dis[M], head[M], cnt, vis[M]; struct Node {int u, v, nxt, w; } G[M];struct Node1 {int u, dis;bool operator < (const Node1 a) const {return this->dis > a.dis;} };priority_queue <Node1> Q;int n, m, k; int s, t;void Link(int u, int v, int w) {G[++ cnt].v = v; G[cnt].u = u; G[cnt].w = w; G[cnt].nxt = head[u]; head[u] = cnt; }void Dijkstra() {memset(dis, 0x3f, sizeof dis);Q.push((Node1){s, 0});dis[s] = 0;while(!Q.empty()) {Node1 tp = Q.top();Q.pop();if(vis[tp.u]) continue;vis[tp.u] = 1;for(int i = head[tp.u]; ~ i; i = G[i].nxt) {int v = G[i].v;if(dis[v] > dis[tp.u] + G[i].w) {dis[v] = dis[tp.u] + G[i].w;Q.push((Node1) {v, dis[v]});}}} }int main() {n = read(), m = read(), k = read();for(int i = 1; i <= n * k + n; i ++) head[i] = -1;s = read() + 1, t = read() + 1;for(int i = 1; i <= m; i ++) {int u = read() + 1, v = read() + 1, w = read();for(int j = 0; j < k; j ++) {Link(j * n + u, j * n + v, w);Link(j * n + v, j * n + u, w);Link(j * n + u, (j + 1) * n + v, 0);Link(j * n + v, (j + 1) * n + u, 0);}Link(n * k + u, n * k + v, w);Link(n * k + v, n * k + u, w);}Dijkstra();int Ans = (1 << 30);for(int i = 0; i <= k; i ++) {Ans = min(Ans, dis[i * n + t]);}cout << Ans;return 0; }

?

轉載于:https://www.cnblogs.com/shandongs1/p/9933195.html

總結

以上是生活随笔為你收集整理的50: Luogu P4568 分层图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。