Hdu 4647 Another Graph Game, thought of as a water question ..

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.