PKU 1273 最大流

來源:互聯網
上載者:User

Source Code</p><p>Problem: 1273 User: zhouxc<br />Memory: 552K Time: 0MS<br />Language: G++ Result: Accepted </p><p>Source Code<br />#include "iostream"<br />#include "queue"</p><p>using namespace std;<br />int m,n,a,b,c,cost[201][201];<br />int Pre[201],Min[201],M=10000001;<br />bool visit[201];</p><p>int Bfs()<br />{<br /> queue<int> q;<br /> int temp;<br /> visit[1]=true;<br /> Pre[1]=0;<br /> Min[1]=M;<br /> q.push(1);<br /> while(!q.empty())<br /> {</p><p> temp=q.front();<br /> q.pop();<br /> if(temp==m)<br /> break;<br /> for(int i=1;i<=m;i++)<br /> {<br /> if(!visit[i]&&cost[temp][i])<br /> {</p><p> Min[i]=(Min[temp]<cost[temp][i]) ? Min[temp] : cost[temp][i];<br /> Pre[i]=temp;<br /> visit[i]=true;<br /> q.push(i);<br /> }<br /> }<br /> }<br /> if(!visit[m])<br /> return -1;<br /> else<br /> return Min[m];<br />}</p><p>void Ford_Fulkerson()<br />{<br /> int f,Max_Flow=0;<br /> while((f=Bfs())!=-1)<br /> {</p><p> int temp=m;<br /> Max_Flow+=f;<br /> memset(visit,false,sizeof(visit));<br /> while(temp!=1)<br /> {<br /> int r=Pre[temp];<br /> cost[r][temp]-=f;<br /> cost[temp][r]+=f;<br /> temp=r;<br /> }<br /> }<br /> printf("%d/n",Max_Flow);<br />} </p><p>int main()<br />{</p><p> while(scanf("%d%d",&n,&m)!=EOF)<br /> {<br /> memset(cost,0,sizeof(cost));<br /> for(int i=1;i<=n;i++)<br /> {<br /> scanf("%d%d%d",&a,&b,&c);<br /> cost[a][b]+=c;<br /> }<br /> Ford_Fulkerson();<br /> } </p><p> return 0;<br />} </p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.