Hdu 4940 passive sink has the largest upstream and downstream streams
/*
Question: A strongly connected graph is provided, each edge has two values: the cost of destroying the edge and the cost of building the edge into a undirected edge (the premise of establishing an undirected edge is to delete the edge) ask if there is a set S, And a set T, which destroys the edge price from all S sets to T sets and is X, then, the edge T to S is replaced by an undirected edge and Y.
Authorization + signature + j1_jkx8/Signature/bAtLXEWSCjqMnPvefWrrrNo6m/Signature/PtqjC + signature "% d", & t); while (t --) {init (); scanf ("% d", & n, & m); S = 0; T = n + 1; memset (w, 0, sizeof (w )); for (I = 1; I <= m; I ++) {scanf ("% d", & a, & B, & c, & d); add (a, B, d); w [B] + = c; w [a]-= c;} sum = 0; for (I = 1; I <= n; I ++) {if (w [I]> 0) {sum + = w [I]; add (S, I, w [I]);} if (w [I] <0) add (I, T,-w [I]);} ans = dinic (S, T ); if (sum = ans) printf ("Case # % d: happy \ n", ++ k); else printf ("Case # % d: unhappy \ n ", + + k);} return 0 ;}