-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path1273.cpp
59 lines (55 loc) · 974 Bytes
/
1273.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
int capacity[203][203]={0};
int flow[203][203]={0};
int e,v;
bool mem[203]={0};
int f(const int x,int y)
{
if(x==v)return y;
int ret=0,i;
mem[x]=1;
for(i=1;i<=v;i++)
{
int dest=i;
if(!mem[i]&&dest!=x&&flow[x][dest]<capacity[x][dest])
{
int nextflow=capacity[x][dest]-flow[x][dest];
if(nextflow>y)nextflow=y;
nextflow=f(dest,nextflow);
y-=nextflow;
ret+=nextflow;
flow[x][dest]+=nextflow;
flow[dest][x]-=nextflow;
}
}
return ret;
}
int main()
{
int i,j,k,l,capatotal=0,maxflow,ret;
while(cin>>e>>v)
{
for(i=0;i<=v;i++)
{
mem[i]=0;
for(j=0;j<=v;j++)
capacity[i][j]=flow[i][j]=0;
}
maxflow=0;
for(i=1;i<=e;i++)
{
cin>>j>>k>>l;
capacity[j][k]+=l;
if(j==1)capatotal+=l;
}
while((ret=f(1,capatotal))>0)
{
maxflow+=ret;
for(i=0;i<=v;i++)
mem[i]=0;
}
cout<<maxflow<<endl;
}
return 0;
}