Another Graph Game

来源:互联网 发布:百佳软件商城 编辑:程序博客网 时间:2024/06/05 20:22
Problem Description
Alice and Bob are playing a game on an undirected graph with n (n is even) nodes and m edges. Every node i has its own weight Wv, and every 
edge e has its own weight We.

They take turns to do the following operations. During each operation, either Alice or Bob can take one of the nodes from the graph that haven’t 

been taken before. Alice goes first.

The scoring rule is: One person can get the bonus attached to a node if he/she have choosen that node before. One person can get the bonus attached to a edge if he/she have choosen both node that induced by the edge before.

You can assume Alice and Bob are intelligent enough and do operations optimally, both Alice and Bob’s target is maximize their score – opponent’s.

What is the final result for Alice – Bob.

 Alice和Bob在一个无向图上进行了一个游戏,其中n(n是偶数)节点和m边。每个结点我都有它自己的权值,每一个边e都有它自己的权值。
他们轮流做下面的操作。在每个操作中,Alice或Bob都可以从图中提取一个节点,而这些节点以前没有被执行过。爱丽丝是第一个。
得分规则是:如果一个人之前选择了那个节点,就可以获得附加到节点的额外奖励。如果他/她选择了之前由边缘引起的两个节点,
那么一个人就可以获得附加的奖励。

你可以假设爱丽丝和鲍勃足够聪明,并且进行最优操作,爱丽丝和鲍勃的目标都是最大化他们的得分-对手的得分。

Alice-Bob的最终结果是什么?

Input
Muilticases. The first line have two numbers n and m.(1 <= n <= 105, 0<=m<=105) The next line have n numbers from W1 to Wn which Wi is the weight of node i.(|Wi|<=109)

The next m lines, each line have three numbers u, v, w,(1≤u,v≤n,|w|<=109) the first 2 numbers is the two nodes on the edge, and the last one is the weight on the edge. 

  第一行有两个数字n和m(1 <= n <= 105, 0<=m<=105)下一行有从W1到Wn的n个数字,这是节点i的权重。(|Wi|<=109)
接下来的m行,每一行有三个数字u,v,w,(1≤u,v≤n,|w|<=109) 前两个数是边的两个节点,最后一个是边的权值。


Output
One line the final result.

 


Sample Input
4 09 8 6 5
 
Sample Output
2
/*题意:
对于一个图,两个人轮流取点,谁取得那个点则获得那个点的价值,而一个人如果取得同一条边的两点,则同时也会获得这条边的价值,两人都按最优方案去取,
最后输出价值之差
思路:
只要将边分半给两个点即可,如果两点同时在一个人身上,那么边的价值也会加上去,如果两点在两个人身上,那么边的价值会被减去
*/
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;#define N 100001int n, m;double a[N];int main(){int i, j, k, x, y;double w;while (~scanf("%d%d", &n, &m)){for (i = 1; i <= n; i++)scanf("%lf", &a[i]);for (i = 1; i <= m; i++){scanf("%d%d%lf", &x, &y, &w);w = w / 2;a[x] += w;a[y] += w;}sort(a + 1, a + 1 + n);double sum1 = 0, sum2 = 0;for (i = 1; i <= n; i++){if (i % 2 == 0)sum1 += a[i];elsesum2 += a[i];}printf("%.0f\n", sum1 - sum2);}return 0;}