hdu 4647 - Another Graph Game(思路题)

摘自题解:

若没有边权,则对点权从大到小排序即可。。

考虑边,将边权拆成两半加到它所关联的两个点的点权中即可。

。。因为当两个人分别选择不同的点时,这一权值将互相抵消。

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
#define M 100010

using namespace std;
int comp(const double a, const double b) { return a<b; }
double node[M];
int main ()
{
    int n, m;
    while(~scanf("%d%d",&n, &m))
    {
        for(int i = 1; i <= n; ++i)
            scanf("%lf",&node[i]);
        int u, v, w;
        for(int i = 1; i <= m; ++i)
        {
            scanf("%d%d%d",&u, &v, &w);
            node[u] += w/2.0;
            node[v] += w/2.0;
        }
        sort(node+1,node+1+n,comp);
        double ans = 0;
        for(int i = n; i >=2; i-=2)
            ans+=node[i]-node[i-1];
        printf("%.0lf\n",ans);
    }
    return 0;
}


posted on 2013-08-06 19:51  Primo...  阅读(97)  评论(0)    收藏  举报