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 <= 300, m <= 5000, T <= 50.
Idea: I was scared when I saw the question. I didn't understand it at first, and I didn't even know how to come out of the sample. Then Dada came to the same group with a fast AC, so he asked for help. The great god is the great god, saving the edge information, using a two-dimensional, three-dimensional array, and then the DP part. Every time the beginning and end points remain unchanged, note that J (starting point) should be from the I-1 to 0, because to determine the edge acquisition, with the flag array and | operation. Then there is the problem of edge weight in the minimum spanning tree. The method of using and querying sets is very simple, so we can get out TT. Finally, f (I) = min (f (I ), F (j) + TT * (I-j) * V + k ).
Code:
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
Using namespace STD;
Struct uses {
Int St, en, VA;
} Tree [10000];
Int road [500] [500] = {0}, F [100], n, Fa [500];
Bool CN [500] [500] [100] = {false}, flag [500] [500] = {false };
Int my_comp (const uses & X, const uses & Y)
{
If (X. Va <Y. Va) return 1;
Return 0;
}
Int root (int x)
{
If (Fa [x]! = X) Fa [x] = root (Fa [x]);
Return Fa [x];
}
Int main ()
{
Int sum, M, T, v, k, I, j, A, B, C, X, Y, T1, T2, P, TOT = 0, ANS, R2, r1;
Cin> N> m> T> V> K;
Memset (F, 127, sizeof (f ));
For (I = 1; I <= m; ++ I)
{
Cin> A> B> C;
If (A> N | B> N) continue;
Road [a] [B] = road [B] [a] = C;
}
Cin> P;
For (I = 1; I <= P; ++ I)
{
Cin> x> Y> T1> T2;
If (road [x] [Y] = 0) continue;
If (T1> T2)
{
A = T1; T1 = t2; t2 =;
}
If (T1> T) continue;
If (T2> T) T2 = T;
For (j = T1; j <= t2; ++ J)
CN [x] [y] [J] = cn [y] [x] [J] = true;
}
F [0] = 0; Tot = 0;
For (I = 1; I <n; ++ I)
For (j = I + 1; j <= N; ++ J)
If (road [I] [J]> 0)
{
++ Tot;
Tree [tot]. St = I;
Tree [tot]. En = J;
Tree [tot]. Va = road [I] [J];
}
Sort (tree + 1, tree + tot + 1, my_comp );
For (I = 1; I <= T; ++ I)
{
Memset (flag, false, sizeof (FLAG ));
For (j = I-1; j> = 0; -- J)
{
Sum = 1;
Ans = 0;
For (A = 1; A <= N; ++)
Fa [a] =;
For (A = 1; A <= tot; ++)
{
Flag [tree [A]. St] [tree [A]. En] =
Flag [tree [A]. st] [tree [A]. en] | (CN [tree [A]. st] [tree [A]. en] [J + 1]);
If (! Flag [tree [A]. St] [tree [A]. En])
{
R1 = root (tree [A]. St );
R2 = root (tree [A]. En );
If (R1! = R2)
{
Fa [R1] = R2;
Ans = ans + tree [A]. Va;
++ Sum;
}
}
If (sum = N) break;
}
If (sum> = N)
F [I] = min (F [I], F [J] + ans * (I-j) * V + k );
}
}
Cout <F [T] <Endl;
}
Tyvj1064 New Three Kingdoms hegemony