-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU-dx15-1006.cpp
132 lines (130 loc) · 2.08 KB
/
HDU-dx15-1006.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
LANG:C++
PROB:milk6
*/
#include <iostream>
#include <string.h>
#include<cstdio>
using namespace std;
#define int64 long long
int64 n,m;
struct edge
{
int64 x,y,f;
}e[200001];
int64 c[1100][1100];
int64 c2[1100][1100];
int64 ans[200001];
void init()
{
//freopen("milk6.out","w",stdout);
scanf("%lld%lld",&n,&m);
int cc=0;
for(int i=1;i<=m;i++)
{
int64 x,y,z,t;
scanf("%lld%lld%lld%lld",&x,&y,&z,&t);
x++;y++;
cc++;
e[cc].x=x;
e[cc].y=y;
e[cc].f=z*100001+1;
c[x][y]+=z*100001+1;
if (t==1)
{
cc++;
e[cc].x=y;
e[cc].y=x;
e[cc].f=z*100001+1;
c[y][x]+=z*100001+1;
}
}
}
class NETFLOW
{
public:
int64 vh[100],h[100];
int64 ans;
int64 flow;
bool found;
void aug(int x)
{
if(x==n)
{
found=true;
ans+=flow;
return;
}
int64 minh=n-1,old=flow,i;
for(i=1;i<=n;i++)
if(c2[x][i]>0)
{
if(h[i]+1==h[x])
{
if(c2[x][i]<flow)
flow=c2[x][i];
aug(i);
if(h[1]>=n) return;
if(found) break;
}
if(minh>h[i])
minh=h[i];
}
if(found)
{
c2[x][i]-=flow;
c2[i][x]+=flow;
}
else
{
vh[h[x]]--;
if(vh[h[x]]==0)
h[1]=n;
h[x]=minh+1;
vh[h[x]]++;
}
}
int64 getmax()
{
memset(h,0,sizeof(h));
memset(vh,0,sizeof(vh));
h[0]=n;
ans=0;
while(h[1]<n)
{
flow=0x7FFFFFFF;
found=false;
aug(1);
}
return ans;
}
}maxflow;
int main()
{
int zu,zz;
freopen("ti.in","r",stdin);
scanf("%d",&zu);
for (zz=1;zz<=zu;zz++)
{
memset(ans,0,sizeof(ans));
init();
memcpy(c2,c,sizeof(c2));
int64 max=maxflow.getmax();
for(int64 i=1;i<=m;i++)
{
if(max==0) break;
memcpy(c2,c,sizeof(c2));
c2[e[i].x][e[i].y]-=e[i].f;
int64 now=maxflow.getmax();
if(now+e[i].f==max)
{
max-=e[i].f;
c[e[i].x][e[i].y]-=e[i].f;
ans[0]++;
ans[ans[0]]=i;
}
}
printf("Case %d: %lld\n",zz,ans[0]);
}
return 0;
}