Bzoj2563 Ali and Peach Games

Source: Internet
Author: User

Time Limit:3 Sec Memory limit:128 MB
submit:701 solved:496 Description Ali and Peaches are playing a game in which the game is performed on a weighted graph g= (V, E), with a node weight of W (v) and a right edge of C (e). The rules of the game are this:
1. Ali and peaches take turns to dye the vertices in the graph, Ali will dye the vertices red, and the peach will dye the vertices pink. The dots that have been dyed are no longer dyed, and each round must be stained with one and only one vertex.
2. To ensure fairness, the number of nodes n is even.
3. After the N/2 wheel game, both people get a vertex collection. For vertex set S, the score is calculated as

The peach was dyed first because it was lost to the peach by the Ali stone scissors cloth. Both want to make their scores more than the other side, and the more the better. If both are using the optimal strategy, the final peach score minus Ali's score is obtained. Input

Enter the first line contains two positive integers n and M, respectively, the number of nodes and the number of sides of the graph G, to ensure that n must be even.
Next N+m line.
The first n rows, an integer w per line, where the K behavior node K weights.
After M lines, each line of three integers separated by a B C, representing a connection node A and Node B side, the weight is C.

Output

The output contains only one integer, minus the Ali score for the peach score.

Sample Input4 4
6
4
-1
-2
1 2 1
2 3 6
3 4 3
1 4 5
Sample Output3
Data size and conventions
For 40% of data, 1≤n≤16.
For 100% of data, 1≤n≤10000,1≤m≤100000,-10000≤w, c≤10000.
HINT Source

2012 National Training Team Round 1 day2

Divide the Benquan into the endpoint so that if a person has an endpoint, the margin will be offset, and if a candidate has two endpoints on an edge, the gain equals the added edge.

Will add the right to the edge of the right from the big to the small sort, the simulation of the two people choose, the results can be poor.

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <queue>6 #defineLL Long Long7 using namespacestd;8 Const intmxn=10100;9 intn,m;Ten DoubleW[MXN]; One intRead () { A     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} the     returnx*F; - } - Doubleans1=0, ans2=0; - intMain () + { -     inti,j,u,v; +N=read (); m=read (); A      for(i=1; i<=n;i++) atW[i]= (Double) read (); -      for(i=1; i<=m;i++){ -U=read (); V=read (); j=read (); -w[u]+= (Double) j/2; -w[v]+= (Double) j/2; -     } inSort (w+1, w+n+1); -      for(i=1; i<=n;i+=2){ toans1+=W[i]; +ans2+=w[i+1]; - //printf ("%.2f%.2f\n", ans1,ans2); the     } *printf"%d\n",(int) (ans2-ans1)); $     return 0;Panax Notoginseng}

Bzoj2563 Ali and Peach Games

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.