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.


 
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. 
 
Output
One line the final result.


 
Sample Input
4 0
9 8 6 5
 
Sample Output
2
题意:
对于一个图。两个人轮流取点。谁取得那个点则获得那个点的价值。而一个人假设取得同一条边的两点。则同一时候也会获得这条边的价值,两人都按最优方案去取。最后输出价值之差
思路:
仅仅要将边分半给两个点就可以,假设两点同一时候在一个人身上,那么边的价值也会加上去,假设两点在两个人身上,那么边的价值会被减去
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std; #define ls 2*i
#define rs 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define rank rank1
const int mod = 10007; int 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];
else
sum2+=a[i];
}
printf("%.0f\n",sum1-sum2);
} return 0;
}

最新文章

  1. 敏捷转型历程 - Sprint3 一团糟的演示会
  2. IO(六)--- 编码和解码
  3. 【腾讯Bugly干货分享】QQ电话适配iOS10 Callkit框架
  4. 密码学初级教程(三)公钥密码RSA
  5. maven源码分析- mvn.bat分析
  6. 字符串模拟赛T2
  7. Uploadify上传Excel到数据库
  8. chrpath工具使用
  9. Java基础学习笔记二十六 JDBC
  10. PS 色调——老照片效果
  11. Spark学习之路 (一)Spark初识
  12. Python 基于python操纵zookeeper介绍
  13. URL在Tomcat服务器端的servlet解析过程
  14. PHP----------PHP自身的性能优化注意事项
  15. 【转载】安装 gephi 软件
  16. 面试----你可以手写一个promise吗
  17. avcodec_open2()分析
  18. Hibernate 一次查询分多次返回 避免内存溢出
  19. js-JavaScript的简介
  20. centos_7.1.1503_src_3

热门文章

  1. Android 系统启动过程详解
  2. create a large size empty file to measure transfer speed
  3. 从串口驱动的移植看linux2.6内核中的驱动模型 platform device &amp; platform driver【转】
  4. Ext中点击某个东西弹出框展示
  5. python学习之-- 动态导入模块
  6. thinkphp函数学习(2)——microtime, memory_get_usage, dirname, strtolower, is_file
  7. 版本控制[0] -&gt; git -&gt; 使用 git 进行版本控制
  8. 四. Java继承和多态7. Java static关键字
  9. spirng整合rmi
  10. [转]WCF RESTful service and WebGrid in ASP.NET MVC 5