Hdu 3987: Minimum number of Splitters
A person needs to reach n-1 n m route entries from the starting point 0. We need to find the minimum number of broken route entries so that they cannot reach the end point from the starting point. Obviously, the minimum number of cut lines is the least. Although the minimum cut traffic is fixed, the number of cut lines is not fixed, which can destroy three or four, this happens only when their total traffic is the same.
Problem: Due to the above situation, their total traffic is the same but the number of lines is different. Now we need to change the edge capacity so that the number of sides is the smallest cut, and the number of lines is not the smallest cut.
There are two official solutions. I chose to expand the stream in the residual network, so that the two minimum cut operations are different. In the residual network, when I add 1 to all side traffic, I can run the maximum flow to get the minimum number of lines to be cut.
Another way is to expand the traffic before running the largest stream, and then process the smallest cut to get the minimum number of cut.
Code
# Include
# Include
# Include
# Define INF 0x3f3f3f
# Define N 1005
Using namespace std;
Int list [N], listt [N], deep [N], tot;
Struct Node
{
Int date, next, value;
} Cun [2, 2000005];
Struct B
{
Int x, t;
} Old, xin;
Void add (int a, int B, int c)
{
Cun [++ tot]. date = B;
Cun [tot]. value = c;
Cun [tot]. next = list [a];
List [a] = tot;
Cun [++ tot]. date =;
Cun [tot]. value = 0;
Cun [tot]. next = list [B];
List [B] = tot;
}
Int bfs (int s, int t, int n)
{
Queue P;
Old. x = s;
Old. t = 0;
P. push (old );
Memset (deep, 255, sizeof (deep ));
Deep [s] = 0;
While (! P. empty ())
{
Old = p. front ();
P. pop ();
For (int I = list [old. x]; I = cun [I]. next)
{
Int date = cun [I]. date;
Int value = cun [I]. value;
If (value = 0 | deep [date]! =-1) continue;
Xin. x = date;
Xin. t = old. t + 1;
Deep [date] = xin. t;
P. push (xin );
}
}
For (int I = 0; I <= n; I ++)
{
Listt [I] = list [I];
}
Return deep [t]! =-1;
}
Int minn (int a, int B)
{
If (a <B) return;
Return B;
}
Int dfs (int s, int t, int min)
{
If (s = t) return min;
Int neww = 0;
For (int I = listt [s]; I = cun [I]. next)
{
Listt [s] = I;
Int date = cun [I]. date;
Int value = cun [I]. value;
If (value = 0 | deep [date]! = Deep [s] + 1) continue;
Int m = dfs (date, t, minn (value, min-neww ));
Neww + = m;
Cun [I]. value-= m;
Cun [I ^ 1]. value + = m;
If (neww = min) break;
}
If (neww = 0) deep [s] = 0;
Return neww;
}
Int dinic (int s, int t, int n)
{
Int num = 0;
While (bfs (s, t, n ))
{
Num + = dfs (s, t, INF );
}
Return num;
}
Int main ()
{
Int n, m, a, B, c, flag, T, flagg = 1;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n, & m );
Memset (list, 0, sizeof (list ));
Tot = 1;
For (int I = 1; I <= m; I ++)
{
Scanf ("% d", & a, & B, & c, & flag );
Add (a + 1, B + 1, c );
If (flag)
Add (B + 1, a + 1, c );
}
Int k = dinic (1, n, n + 5 );
For (int I = 2; I <= tot; I + = 2)
{
Cun [I]. value ++;
}
K = dinic (1, n, n + 5 );
Printf ("Case % d: % d \ n", flagg ++, k );
}
}