POJ-1698 Alice's maximum chance stream

Source: Internet
Author: User

No sap, and the adjacent matrix is too large.

# Include <cstdlib>
# Include <cstring>
# Include <cstdio>
# Include <queue>
# Define maxn375
# Define INF 0x3f3f3f
Using namespace STD;

Int CAP [maxn + 1] [maxn + 1], flow [maxn + 1] [maxn + 1], N;
Int P [maxn + 1], C [maxn + 1];
Int seq [25] [15], maxflow;

Inline void Init ()
{
Maxflow = 0;
Memset (Cap, 0, sizeof (CAP ));
Memset (flow, 0, sizeof (flow ));
}

Inline int min (int A, int B)
{
Return a <B? A: B;
}

Void BFS ()
{
Int finish = 0, Pos;
While (! Finish ){
Memset (C, 0, sizeof (c); // record the push traffic
C [0] = inf;
Queue <int> q;
Q. Push (0 );
While (! Q. Empty ()){
If (C [maxn])
Break;
Pos = Q. Front ();
Q. Pop ();
For (INT I = 0; I <= maxn; ++ I ){
If (! C [I] & flow [POS] [I] <CAP [POS] [I]) {
C [I] = min (C [POS], Cap [POS] [I]-flow [POS] [I]);
P [I] = Pos;
Q. Push (I );
}
}
}
Maxflow-= C [maxn];
If (C [maxn] = 0 ){
Finish = 1;
Break;
}
Pos = maxn;
While (Pos! = 0 ){
Flow [p [POS] [POS] + = C [maxn];
Flow [POS] [p [POS]-= C [maxn];
Pos = P [POS];
}
}
}

Int main ()
{
Int T;
Scanf ("% d", & T );
While (t --){
Init ();
Scanf ("% d", & N );
For (INT I = 0; I <n; ++ I ){
For (Int J = 0; j <9; ++ J ){
Scanf ("% d", & seq [I] [J]);
}
Maxflow + = seq [I] [7];
Cap [0] [I + 1] = seq [I] [7];
For (Int J = 0; j <7; ++ J ){
If (SEQ [I] [J]) {
For (int K = 0; k <seq [I] [8]; ++ K ){
Cap [I + 1] [K * 7 + n + 1 + J] = 1;
Cap [K * 7 + n + 1 + J] [maxn] = 1;
}
}
}
}
BFS ();
If (maxflow = 0 ){
Puts ("yes ");
}
Else {
Puts ("no ");
}
}
Return 0;
}

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.