The question is to give an undirected graph, with each node having a bit of permission and edge permission. Then two children started to play the game. ALICE and BOB set ALICE to act first and then BOB, then take turns in turn. During the action, you can select a node and obtain the node's point permission. If he has already obtained the two endpoints of one edge, then he can get the edge right over there. If the two ends of one edge have different people, then no one will get the edge right. After the game is over, how can ALICE get the weight and subtract BOB's weight and the maximum? Of course, both of them are equally smart, that is, every action will adopt the best strategy.
Solution: If no Edge Weight exists, sort the point weights in ascending order .. Consider the edge, split the edge right into two halves and add it to the vertex right of the two points associated with it... Because when two people select different points, this weight will offset each other.
Think about it, because the final result is the difference...
It should be noted that there is nothing to do with long. In order to avoid the score when the edge is split, you can calculate the result by two times and divide the final output by two.
The following code is used:
# Include <cstdio >#include <algorithm> bool inline cmp (long a, long B) {return a> B ;} // The long node [100005], ans; int N, M; int read () {if (scanf ("% d", & N, & M )! = 2) return 0; for (int I = 1; I <= N; I ++) {scanf ("% I64d", & node [I]); node [I] * = 2; // point weight twice of storage} for (int a, B, c, I = 0; I <M; I ++) {scanf ("% d", & a, & B, & c); node [a] + = c, node [B] + = c; // do not divide edges by 2} std: sort (node + 1, node + N + 1, cmp); // descending order ans = 0; for (int I = 0; I <N/2; I ++) ans + = node [2 * I + 1]-node [2 * I + 2]; // calculation result printf ("% I64d \ n", ans/2); // The output result is divided by two return 1;} int main () {// freopen ("in.txt", "r", stdin); while (read (); return 0 ;}