Hdu 3987: Minimum number of Splitters

Source: Internet
Author: User

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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.