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>