The largest stream in the upper and lower circles. It is easy to create a graph. The number of days is connected to the source point, and the capacity is the maximum number of photos taken every day. The girl connects to the sink. The capacity is INF. Based on the range that each girl can take every day, she creates a picture to find the largest stream in the upper and lower circles. I tried dinic. After that, note that a line feed should be output.
Shoot the bullet
Time Limit: 2 seconds
Memory limit: 32768 kb Special Judge
GensokyoIs a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies,Youkai(Phantoms), and gods live peacefully together. shameimaru Aya is a crow Tengu
The ability to manipulate wind who has been inGensokyoFor over 1000 years. She runs the bunbunmaru news-a newspaper chock-full of rumors, and ownsBunkachou-Her record of interesting observations for bunmaru news articles and pictures
Of beautifulDanmaku(Barrange) or cute girls living inGensokyo. She is the biggest connoisseur of rumors about the girlsGensokyoAmong the Tengu. Her intelligence gathering abilities are the best inGensokyo!
During the comingNDays, Aya is planning to take over photos
MCute girls living inGensokyoTo write bunbunmaru News Daily and record at least
GXPhotos of girlXIn total inBunkachou. At
K-Th day, there areCKTargets,TK1,
Tk2,...,Tkck. The number of photos of target
TKIThat Aya takes shocould be in range [Lki,
RKI], If less, Aya cannot write an interesting article, if more, the girl will become angry and use her
Last spell cardTo attack Aya. What's more, Aya cannot take more
DKPhotos atK-Th day.Under these constraints, the more photos, the better.
Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.
Input
There are about 40 cases. process to the end of file.
Each case begins with two integers 1 <=N& Lt; = 365, 1 & lt; =M<= 1000. Then
MIntegers,G1,G2,...,GMIn range [0, 10000]. Then
NDays. Each day begins with two integer 1 <=C& Lt; = 100, 0 & lt; =
D<= 30000. ThenC DifferentTargets. Each target is described by three integers, 0 <=
T<M, 0 <=L<=R<= 100.
Output
For each case, first output the number of photos Aya can take,-1 if it's impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya shocould take at each day on separate lines. The output
Must be in the same order as the input. If there are more than one best strategy, any one will be OK.
Output a blank line after each case.
Sample Input
2 312 12 123 180 3 91 3 92 3 93 180 3 91 3 92 3 92 312 12 123 180 3 91 3 92 3 93 180 0 31 3 62 6 92 312 12 123 150 3 91 3 92 3 93 210 0 31 3 62 6 12
Sample output
3666666636963369-1# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> using namespace STD; # define maxn 20010 # define maxm 1000010 # define INF 0 xffffffstruct edge {int to, C, next ;}; edge e [maxm]; int n, m; int que [maxn * 100], DIS [maxn], pre [maxn], maxflow; int head [maxn], head2 [maxn], en, vn; int St, Ed; int in [maxn], low [maxm]; int girl [1500], day [500]; void add (int A, int B, int c) {e [En]. to = B; E [En]. C = C; E [En]. nex T = head [a]; head [a] = EN ++; E [En]. to = A; E [En]. C = 0; E [En]. next = head [B]; head [B] = EN ++;} bool BFS () {memset (DIS,-1, sizeof (DIS )); que [0] = ST, DIS [st] = 1; int T = 1, F = 0; while (F <t) {Int J = que [f ++]; for (int K = head [J]; k! =-1; k = E [K]. next) {int I = E [K]. to; If (DIS [I] =-1 & E [K]. c) {que [t ++] = I; DIS [I] = dis [J] + 1; if (I = ed) return true ;}}} return false;} int Update () {int P, flow = inf; For (INT I = pre [ed]; I! =-1; I = pre [I]) if (E [head2 [I]. c <flow) P = I, flow = E [head2 [I]. c; For (INT I = pre [ed]; I! =-1; I = pre [I]) E [head2 [I]. c-= flow, E [head2 [I] ^ 1]. c + = flow; maxflow + = flow; return P;} void DFS () {memset (PRE,-1, sizeof (pre); memcpy (head2, Head, sizeof (head2); For (INT I = ST, J; I! =-1;) {int flag = false; For (int K = head [I]; k! =-1; k = E [K]. next) if (E [K]. C & (DIS [J = E [K]. to] = dis [I] + 1) {pre [J] = I; head2 [I] = K; I = J; flag = true; if (I = ed) I = Update (); If (FLAG) break;} If (! Flag) dis [I] =-1, I = pre [I] ;}} int dinic () {int ans = 0; maxflow = 0; while (BFS ()) DFS (); Return maxflow;} int limitflow () {int I, st0, ed0, en0, ret = 0; st0 = ST, ed0 = ed, en0 = en; st = Vn ++, ED = Vn ++; head [st] = head [ed] =-1; for (I = 0; I <vn-2; ++ I) {If (in [I]> 0) add (St, I, in [I]); If (in [I] <0) add (I, Ed, -In [I]);} Add (ed0, st0, INF); dinic (); for (I = head [st]; I! =-1; I = E [I]. next) if (E [I]. c) Return-1; ST = st0, ED = ed0; For (VN-= 2, I = 0; I <VN; ++ I) while (head [I]> = en0) head [I] = E [head [I]. next; dinic (); for (I = head [st]; I! =-1; I = E [I]. next) RET + = E [I ^ 1]. c; return ret;} void solve () {ST = 0, ED = N + m + 1, vn = N + m + 2, en = 0; memset (Head, -1, sizeof (head); memset (in, 0, sizeof (in); For (INT I = 1; I <= m; I ++) scanf ("% d", & Girl [I]); int NN, no, l, R; int counts = 0; For (INT I = 1; I <= N; I ++) {scanf ("% d", & NN, & day [I]); For (Int J = 1; j <= nn; j ++) {scanf ("% d", & No, & L, & R); no ++; add (I, n + NO, R-L ); in [I]-= L; in [n + NO] + = L; low [counts ++] = L ;}} for (INT I = 1; I <= m; I ++) {Add (I + N, Ed, INF); In [I + N]-= Girl [I]; In [ed] + = Girl [I];} For (INT I = 1; I <= N; I ++) add (St, I, day [I]); // only the upper limit int ret = limitflow (); If (ret =-1) {printf ("-1 \ n"); return;} printf ("% d \ n", RET); For (INT I = 0; I <counts; I ++) printf ("% d \ n", E [(I * 2) ^ 1]. c + low [I]); printf ("\ n");} int main () {While (scanf ("% d", & N, & M )! = EOF) solve (); Return 0 ;}