HDU 1532 最大流模板題

來源:互聯網
上載者:User

標籤:

題目:http://acm.hdu.edu.cn/showproblem.php?pid=1532

最近在學網路流,學的還不好,先不寫理解了,先放模板。。。

 我覺得寫得不錯的部落格:http://blog.csdn.net/smartxxyx/article/details/9293665/

 1 #include<stdio.h> 2 #include<string.h> 3 #include<vector> 4 #define maxn 222 5 #define inf 0x3f3f3f3f 6 using namespace std; 7 struct edge{ 8     int to; 9     int cap;10     int rev;11 };12 vector<edge>e[maxn];13 int book[maxn];14 int dfs(int cur,int end,int flow){15     if(cur == end)16         return flow;17     book[cur] = 1;18     for(int i = 0;i<e[cur].size();i++){19         edge &temp = e[cur][i];20         if(!book[temp.to] && temp.cap>0){21             int d = dfs(temp.to,end,min(flow,temp.cap));22             if(d > 0){23                 temp.cap -= d;24                 e[temp.to][temp.rev].cap += d;25                 return d;26             }27         }28     }29     return 0;30 }31 int main(){32     int n,m;33     while(scanf("%d%d",&n,&m)!=EOF){34         for(int i = 1;i<=n;i++)35             e[i].clear();36         int u,v,w;37         for(int i = 0;i<n;i++){38             scanf("%d%d%d",&u,&v,&w);39             e[u].push_back((edge){v,w,e[v].size()});40             e[v].push_back((edge){u,0,e[u].size()-1});41         }    42         int ans = 0;43         while(1){44             memset(book,0,sizeof(book));45             int temp = dfs(1,m,inf);46             if(temp == 0)47                 break;48             ans += temp;49         }50         printf("%d\n",ans);51     }52     return 0;53 } 

 

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.