标签:html .com ems class i++ const sharp logs lap
入门题:poj1273
题意:求最大流
题解:直接套用网络流的模板,注意,如果重边,那么将边加起来,而不是取最大值,注意:这题多组输入
#include <cstdio> #include <iostream> #include <cstring> #include <ctime> #include <cstdlib> #include <vector> #include <stack> #include <algorithm> #include <map> #include <queue> using namespace std; #define ll long long const int maxn=210; const int maxm=210; ll ma[maxn][maxn]; bool vis[maxn]; int pre[maxn],n,m;; ll get_path(int s,int t) { for(int i=0; i<maxn; i++)vis[i]=0,pre[i]=-1; queue<int>que; que.push(s); vis[s]=1; ll res=1e9; while(que.size()) { int x=que.front(); que.pop(); for(int i=1; i<=n; i++) { if(vis[i]==0&&ma[x][i]!=0) { vis[i]=1; pre[i]=x; res=min(res,ma[x][i]); que.push(i); if(i==t)return res;//到达终点 } } } return 0;//无法到达终点 } void updata(int t,int add)//更新边 { int i=t; while(pre[i]!=-1) { ma[pre[i]][i]-=add; ma[i][pre[i]]+=add; i=pre[i]; } } int main() { while(cin>>m>>n) { memset(ma,0,sizeof(ma)); for(int i=1; i<=m; i++) { ll a,b,c; scanf("%lld %lld %lld",&a,&b,&c); ma[a][b]+=c; } ll ans=0; while(1) { int add=get_path(1,n); if(add==0)break; updata(n,add); ans+=add; } cout<<ans<<endl; } return 0; }
标签:html .com ems class i++ const sharp logs lap
原文地址:https://www.cnblogs.com/carcar/p/9736450.html