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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ 1273 Drainage Ditches 最大流

發布時間:2023/12/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1273 Drainage Ditches 最大流 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

很裸的最大流問題,不過注意會有重邊,o(╯□╰)o,被陰了WA了一發 還有就是要用long long

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list> #include <set> #include <queue> #include <stack>using namespace std;typedef long long LL; const int maxn = 205; const int maxm = 205; const int INF = INT_MAX / 2; LL flow[maxn][maxn],C[maxn][maxn]; int n,m;void input() {memset(C,0,sizeof(C));for(int i = 1;i <= m;i++) {int a,b,c; scanf("%d%d%d",&a,&b,&c);C[a][b] += c;} }LL alpha[maxn]; int pre[maxn]; int q[maxn + 20],qs,qe;void solve() {int s = 1,t = n;memset(flow,0,sizeof(flow));while(1) {for(int i = s + 1;i <= t;i++) pre[i] = -2;pre[s] = -1;qs = 0; qe = 1; q[qs] = s;alpha[s] = 1e13;while(qs < qe && pre[t] == -2) {int v = q[qs]; qs++;for(int i = s;i <= t;i++) {if(pre[i] == -2 && C[v][i] - flow[v][i] != 0) {alpha[i] = min(alpha[v],C[v][i] - flow[v][i]);pre[i] = v;q[qe++] = i;}}}if(pre[t] == -2) break;for(int i = t;pre[i] != -1;i = pre[i]) {flow[pre[i]][i] += alpha[t];flow[i][pre[i]] = -flow[pre[i]][i];}}LL ans = 0;for(int i = s;i < t;i++) ans += flow[i][t];printf("%lld\n",ans); }int main() {while(scanf("%d%d",&m,&n) != EOF) {input();solve();}return 0; }

  

轉載于:https://www.cnblogs.com/rolight/p/3869683.html

總結

以上是生活随笔為你收集整理的POJ 1273 Drainage Ditches 最大流的全部內容,希望文章能夠幫你解決所遇到的問題。

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