There are n garbage dumps on the wide river, and each garbage can only stand for C people. There are m people on the other side of the river who want to cross the river through the garbage. Of course, if the river is narrow, they can directly cross the river. Each person can jump d far at most once and ask those who cross the river in the shortest time.
Practice: This question cannot be done with a charge stream, because everyone can stop on the garbage and then jump over. Therefore, the dynamic stream method is used to divide the graph into layers based on the timeline. In this way, the time is enumerated first, and then the question is done in the largest way. I learned some macro function definitions based on the practices of Daniel.
# Include <stdio. h> # include <string. h> # define EPS 1e8 # define LMT 55 # define T (X, I) (x) + (I-1) * 50) // Add differences at each time. # Define CH (x) + 5000) # define TT 11274 // TT definition error at the beginning, falls into an infinite loop typedef struct {int X, Y;} node; typedef struct {int U, V, next, C ;}line; node nod [LMT * 205]; line E [(LMT * LMT + LMT) * 205]; int next [LMT * 205], Cap [LMT], lie [LMT * 205], Q [LMT * 205], L [LMT * 205]; bool mat [LMT] [LMT]; int all, n, m, D, W; int test (int A, int B) {return (nod [A]. x-nod [B]. x) * (nod [A]. x-nod [B]. x) + (nod [A]. y-nod [B]. y) * (nod [A]. y-nod [B]. y) <= D * D;} void insert (int u, Int V, int c) {e [all]. U = u; E [all]. V = V; E [all]. C = C; E [all]. next = next [u]; next [u] = All ++; E [all]. U = V; E [all]. V = u; E [all]. C = 0; E [all]. next = next [v]; next [v] = All ++;} int BFS (int s, int t) {int U, V, X, Head, tail; memset (maid); Head = tail = 0; Q [tail ++] = s; lev_[ S] = 1; while (Head <tail) {u = Q [head ++]; for (x = next [u]; X! =-1; X = E [X]. next) {v = E [X]. v; If (lev[ v] = 0 & E [X]. c> 0) {lev[ v] = lev[ u] + 1; Q [tail ++] = V ;}} return lev[ T]! = 0;} int DFS (int s, int t) {int U, V, X, Top = 0, ret = 0; Q [top ++] = s; while (top> 0) {u = Q [Top-1]; If (u = T) {int back, I, min = EPS + 10; for (I = 1; I <top; I ++) {x = L [Q [I]; If (min> E [X]. c) {x = L [Q [I]; min = E [X]. c; back = I ;}} RET + = min; for (I = 1; I <top; I ++) {x = L [Q [I]; E [X]. c-= min; E [x ^ 1]. c + = min;} Top = back;} else {for (x = next [u]; X! =-1; X = E [X]. next) {v = E [X]. v; If (maid [v] = maid [u] + 1 & E [X]. c> 0) {q [top ++] = V; L [v] = x; break ;}} if (x =-1) {EV [u] = 0; top -- ;}} return ret;} int dinic (int s, int t) {int ret = 0; while (BFS (S, t) RET + = DFS (S, T); return ret;} int main () {int I, J, K, get = 0, S, T; scanf ("% d", & N, & M, & D, & W); memset (MAT, 0, sizeof (MAT )); memset (next,-1, sizeof (next); All = 0; S = 0; t = tt; for (I = 1; I <= N; I ++) scanf ("% d", & nod [I]. x, & n Od [I]. y, & Cap [I]); for (I = 1; I <= N; I ++) for (j = I + 1; j <= N; j ++) if (test (I, j) mat [I] [J] = mat [J] [I] = 1; if (D> = W) {printf ("1 \ n"); Return 0 ;}for (I = 1; I <= N + m; I ++) {for (j = 1; j <= N; j ++) {insert (T (J, I), CH (T (J, I), Cap [J]); if (nod [J]. y-D <= 0) insert (S, T (J, I), EPS); If (nod [J]. Y + D> = W) insert (CH (T (J, I), T, EPS); For (k = 1; k <= N; k ++) if (MAT [J] [k]) insert (CH (T (J, I), T (K, I + 1), EPS ); // It takes one second for a hop. Therefore, the point of the I moment can only be connected to the I + 1 moment.} Get + = dinic (S, T); If (get> = m) break;} If (get <m) printf ("impossible \ n "); else printf ("% d \ n", I + 1); Return 0 ;}