BZOJ 2563 raccoon and peach game greedy, bzoj2563

Source: Internet
Author: User

BZOJ 2563 raccoon and peach game greedy, bzoj2563

Given an undirected graph, each vertex has a certain weight, and each edge has an edge weight. Two people choose points in turn. If the two ends of an edge are selected, the edge is selected, both of them want their own scores-the opponent has the largest score, and the final first hand score-the latter hand score

Consider the impact of first-hand selection of each point on the answer

If you do not select a point, the contribution to the answer is-w.

If you select a point, the contribution to the answer is w.

If neither of the two endpoints is selected, the contribution to the answer is-c.

If only one of the two endpoints is selected, the contribution to the answer is 0.

If both endpoints are selected, the contribution to the answer is c.

Then we first subtract all the weights from the initial answer in advance, and then it becomes:

If you do not select a point, the contribution to the answer is 0.

If you select a point, the contribution to the answer is.

If neither of the two ends of an edge is selected, the contribution to the answer is 0.

If only one of the two endpoints is selected, the contribution to the answer is c.

If both endpoints are selected, the contribution to the answer is 2 * c

So that the contribution of a vertex is twice the vertex weight + the edge weight of all connected Edges

Sort the order to take the maximum order.

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 10100using namespace std;int n,m;long long ans,a[M];int main(){int i,x,y,z;cin>>n>>m;for(i=1;i<=n;i++){scanf("%d",&z);ans-=z;a[i]=z<<1;}for(i=1;i<=m;i++){scanf("%d%d%d",&x,&y,&z);ans-=z;a[x]+=z;a[y]+=z;}sort(a+1,a+n+1);for(i=2;i<=n;i+=2)ans+=a[i];cout<<ans<<endl;return 0;}


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.