hdu 4647 Another Graph Game 博弈

http://acm.hdu.edu.cn/showproblem.php?pid=4647

树上的博弈,直接把边权平分到两边的节点上,然后排个序,从大往小取

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int n , m;
double a[maxn];
int main() {
    while(~scanf("%d%d",&n,&m)) {
        for(int i=1;i<=n;i++) scanf("%lf" , &a[i]);
        int u , v;
        double w;
        while(m--) {
            scanf("%d%d%lf",&u,&v,&w);
            w /= 2.0;
            a[u] += w; a[v] += w;
        }
        sort(a+1 , a+n+1);
        double ans = 0;
        for(int i=n;i>=1;i-=2) {
            ans += a[i] - a[i-1];
        }
        printf("%.0lf
" , ans);
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/tobec/p/3246477.html