Description
PP is especially fond of playing instant strategy games, but he thinks those games have weaknesses. Disasters always fall on the road, but only on the city, and the road cannot be occupied, without protecting the authenticity of grain and grass. So he developed the New Three Kingdoms competition.
In this game, add the effects of disasters on roads (that is, once the Road W [I, j] is affected by disasters, this road will not pass within a certain period of time) and the right to occupy the road (for a road W [I, j], at least K [I, j] soldiers are required to hold it ).
PP can be really a master, not a while, it took the N-1 city, plus the original n cities, but he ignored a little ...... That is, defense is equally important, but now we are still here. Many cities need to be built only after the battle. It may take about t days for PP to estimate. Now he has no time to stand alone and attack, so he has to make a good effort in the past t days. So he had to send soldiers to occupy some roads to ensure that there was a road between any two cities (or the enemy would have to attack it separately, which was very dangerous ). Soldiers do not work in the white space. Every soldier eats V's military grain every day. Due to disasters, the Scheme may change (K's military grain is required for every change, and K's military grain is also required for the initial scheme ).
Because the game is made up by PP, he knows when there will be a disaster. PP is a very economical person. He hopes to spend the least effort on road defense this day.
\ (N \ leq300 \), \ (M \ leq5000 \), \ (T \ leq50 \)
Input description input description
The first line contains 5 integers \ (n \), \ (M \), \ (T \), \ (V \), \ (k \). \ (N \) indicates the number of cities, \ (M \) indicates the number of roads, \ (T \) indicates the number of days to cultivate, \ (V \) the number of military grain that each soldier eats every day. \ (k \) indicates the number of military grain consumed once.
The following m rows have three numbers \ (A \), \ (B \), and \ (C \). It indicates that \ (A \) and \ (B \) have a path (which is bidirectional) and must be held by \ (C \) soldiers.
Row \ (m + 2 \) is a number P, indicating \ (P \) disasters.
The following P rows have four numbers \ (x \), \ (Y \), \ (T_1 \), and \ (T_2 \). This path from X to Y is affected by disasters in the \ (T_1 \) to \ (T_2 \) days.
Output description
\ (T \) days spent the least effort on road defense.
Sample Input
3 3 5 10 301 2 12 3 21 3 411 3 2 5
Sample output sample output
180
Data size & hint
Test points \ (1 S \)
Solution
Emmmm has nothing to say.
For such things, which can remain unchanged for a period of time can basically be DP. Today, I don't know what my mind looks like. I thought about this naked question for a long time.
Then, Kruskal is used for preprocessing to obtain the minimum cost of using the same State from \ (I \) to \ (J \) \ (W [I] [J] \). And then directly transfer the code. Order \ (DP [I] \) represents the minimum cost of day \ (I.
\ [DP [I] = min \ {DP [J] + W [J + 1] [I] \ times v * (I-j) + k | 0 \ Leq j <I \} \]
# Include <cstdio> # include <algorithm> # include <cmath> # include <cstring> using namespace STD; # define lowbit (x) (X) & (-(X) # define rep (I, A, n) for (register int I = (a); I <= (n); ++ I) # define per (I, A, n) for (register int I = (a); I >=( N); -- I) # define FEC (I, X) for (register int I = head [X]; I; I = G [I]. ne) # define dbg (...) fprintf (stderr ,__ va_args _) namespace Io {const int size = (1 <21) + 1; char ibuf [size], * is, * It, obuf [size], * OS = Obuf, * ot = OS + size-1, C, Qu [55]; int F, Qr; # define GC () (is = It? (It = (is = ibuf) + fread (ibuf, 1, size, stdin), (is = It? EOF: * Is ++) inline void flush () {fwrite (obuf, 1, OS-obuf, stdout); OS = obuf ;} inline void putc (char X) {* OS ++ = x; If (OS = ot) flush () ;}template <class I> inline void read (I & X) {for (F = 1, C = GC (); C <'0' | C> '9'; C = GC ()) if (C = '-') F =-1; for (x = 0; C <= '9' & C> = '0 '; C = GC () x = x * 10 + (C & 15); x * = f;} template <class I> inline void write (I X) {If (! X) putc ('0'); If (x <0) putc ('-'), x =-X; while (X) qu [++ QR] = x % 10 + '0', X/= 10; while (QR) putc (qu [QR --]);} struct flusher _{~ Flusher _ () {flush () ;}} io_flusher _ ;}// orz laofudasuanusing IO: read; using IO: putc; using IO: write; typedef long ll; typedef unsigned long ull; Template <typename A, typename B> inline bool Smax (A & X, const B & Y) {return y> X? X = Y, 1:0;} template <typename A, typename B> inline bool Smin (A & X, const B & Y) {return Y <X? X = Y, 1:0;} const int n = 300 + 7, M = 5000 + 7, t = 50 + 7, INF = 0x3f3f3f3f; int n, m, T, V, k, P, X, Y, T1, T2, FBD [T] [N] [N], DP [T], W [N] [N]; struct edge {int x, y, z; inline bool operator <(const edge & A) const {return z <. Z ;}} G [m]; int Fa [N]; inline int find (int x) {return Fa [x] = x? X: Fa [x] = find (Fa [x]);} inline void Union (int x, int y) {x = find (x ), y = find (y); Fa [y] = x;} inline bool check (int A, int B, int L, int R) {for (register int I = L; I <= r; ++ I) if (FBD [I] [a] [B]) return 1; return 0;} inline int Kruskal (INT L, int R) {for (register int I = 1; I <= N; ++ I) Fa [I] = I; int ans = 0; For (register int I = 1, CNT = 0; I <= m; ++ I) {int x = G [I]. x, Y = G [I]. y, Z = G [I]. z; If (find (x) = find (y) | check (X, Y, L, R) continue; Union (x, y); ++ CN T; ans + = z; If (CNT = N-1) return ans;} inline void dp () {DP [0] = 0; for (register int I = 1; I <= T; ++ I) {DP [I] = inf; For (register Int J = 0; j <I; ++ J) Smin (DP [I], DP [J] + W [J + 1] [I] * V * (I-j) + k );}} int main () {# ifndef online_judge freopen ("cv1403.in", "r", stdin); freopen ("cv1403.out", "W", stdout ); # endif read (N), read (M), read (t), read (V), read (k); For (register int I = 1; I <= m; ++ I) read (G [I]. x), read (G [I]. y), read (G [I]. z); Sort (G + 1, G + m + 1); read (p); For (register int I = 1; I <= P; ++ I) {read (x), read (Y), read (T1), read (T2); For (register Int J = T1; j <= t2; ++ J) FBD [J] [x] [Y] = FBD [J] [y] [x] = 1 ;}for (register int I = 1; I <= T; ++ I) for (register Int J = I; j <= T; ++ J) W [I] [J] = Kruskal (I, j); DP (); write (DP [T]), putc ('\ n'); // error note: the output is DP [T]!}
Codevs1403 New Three Kingdoms hegemony