hdu 1532 逾時

來源:互聯網
上載者:User

標籤:

#include <bits/stdc++.h>using namespace std;const int INF=0x3f3f3f3f;typedef long long LL;#define PI(A) printf("%d\n",A)#define SI(N) scanf("%d",&(N))#define SII(N,M) scanf("%d%d",&(N),&(M))#define cle(a,val) memset(a,(val),sizeof(a))#define rep(i,b) for(int i=0;i<(b);i++)#define Rep(i,a,b) for(int i=(a);i<=(b);i++)#define reRep(i,a,b) for(int i=(a);i>=(b);i--)const double EPS= 1e-9 ;/*  /////////////////////////     C o d i n g  S p a c e     /////////////////////////  */const int MAX_V= 1000 + 5 ;struct edge{int to,cap,rev;};vector<edge> G[MAX_V];int level[MAX_V];int iter[MAX_V];void add_edge(int from,int to,int cap){    G[from].push_back((edge){to,cap,G[to].size()});    G[to].push_back((edge){from,0,G[from].size()-1});}void bfs(int s){    memset(level,-1,sizeof(level));    queue<int> que;    level[s]=0;    que.push(s);    while(!que.empty())    {        int v=que.front();que.pop();        for (int i=0;i<G[v].size();i++)        {            edge& e=G[v][i];            if (e.cap>0&&level[e.to]<0)            {                level[e.to]=level[v]+1;                que.push(e.to);            }        }    }}int dfs(int v,int t,int f){    if (v==t) return f;    for (int i=iter[v];i<G[v].size();i++)    {        edge& e=G[v][i];        if (e.cap>0&&level[v]<level[e.to])        {            int d=dfs(e.to,t,min(f,e.cap));            if (d>0)            {                e.cap-=d;                G[e.to][e.rev].cap+=d;                return d;            }        }    }    return 0;}int max_flow(int s,int t){    int flow=0;    for (;;)    {        bfs(s);        if (level[t]<0) return flow;        memset(iter,0,sizeof(iter));        int f;        while((f=dfs(s,t,INF))>0)        {            flow+=f;        }    }}int main(){#ifndef ONLINE_JUDGE    freopen("C:\\Users\\Zmy\\Desktop\\in.txt","r",stdin);//    freopen("C:\\Users\\Zmy\\Desktop\\out.txt","w",stdout);#endifiostream::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int n,m;while(cin>>n>>m){    int ans=0;    for (int i=0;i<n;i++)    {        int u,v,w;        cin>>u>>v>>w;        add_edge(u,v,w);        ans+=max_flow(1,m);    }    printf("%d\n",ans);}    return 0;}

 

hdu 1532 逾時

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.