HDU-4647 Another Graph Game 貪心

來源:互聯網
上載者:User

標籤:acm   hdu   多校   

將邊權拆成兩半加到它所關聯的兩個點的點權中即可。因為當兩個人分別選擇不同的點時,這一權值將互相抵消。然後排序從最優開始取。

#include <iostream>#include <cstdio>#include <cmath>#include <queue>#include <algorithm>#include <iomanip>#include <cstring>#include <vector>#define LL long longusing namespace std;const int maxn=110000;bool cmp(LL a, LL b){return a>b;}LL n,m;LL w[maxn];int main(){LL u,v,l;while(scanf("%I64d%I64d",&n,&m)!=EOF){for(LL i=1;i<=n;i++){scanf("%I64d",&w[i]);w[i]*=2ll;}for(LL i=0;i<m;i++){scanf("%I64d%I64d%I64d",&u,&v,&l);w[u]+=l;w[v]+=l;}sort(w+1,w+1+n,cmp);LL k=1;LL s1=0ll;LL s2=0ll;while(k<=n){if(k%2==1){s1+=w[k];}else{s2+=w[k];}k++;}LL ans=s1-s2;printf("%I64d\n",ans/2);}return 0;}


HDU-4647 Another Graph Game 貪心

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.