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