Another Graph Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 601 Accepted Submission(s): 216
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.
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.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
//
const int V = 100000 + 50;
const int MaxN = 80 + 5;
const int mod = 10000 + 7;
const __int64 INF = 0x7FFFFFFFFFFFFFFFLL;
const int inf = 0x7fffffff;
int n, m, ans;
double num[V];
bool cmp(__int64 a, __int64 b) {
return a > b;
}
int main() {
int i, j;
while(~scanf("%d%d", &n, &m)) {
for(i = 1; i <= n; ++i)
scanf("%lf", &num[i]);
while(m--) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
num[u] += w / 2.0;
num[v] += w / 2.0;
}
sort(num + 1, num + n + 1, cmp);
double a, b;
a = b = 0.0;
for(i = 1; i <= n; ++i) {
if(i % 2 == 1)
a += num[i];
else
b += num[i];
}
printf("%I64d\n", (__int64)(a - b));
}
}