【bzoj2563】阿狸和桃子的游戏

Source and Judge

bzoj2563

Analysis

请先思考后再展开

那么对于点,选+w,不选-w
对于边,选2个点+c,选一个点+0,选0个点-c
那么把边权分摊到点权上,然后轮流取即可

然后如果要求具体值的话,就通过选的点判断即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
typedef long long ll;
const int INF=0x3f3f3f3f;
ll qread()
{
ll ans=0;char c=getchar();int f=1;
while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
return ans*f;
}
void write(int num)
{
if(num<0) {num=-num;putchar('-');}
if(num>9) write(num/10);
putchar('0'+num%10);
}
void writeln(int num){write(num);puts("");}
#define pr pair<int,int>
#define FR first
#define SE second
#define MP make_pair
inline void chmin(ll &x,ll y) {x=x<y?x:y;}
const int MAX_N=11000;
double a[MAX_N];priority_queue<double> q;
void main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
while(m--)
{
int x,y,c;scanf("%d%d%d",&x,&y,&c);
a[x]+=c/2.0;a[y]+=c/2.0;
}
for(int i=1;i<=n;i++) q.push(a[i]);
double ans=0;
while(q.size())
{
ans+=q.top();q.pop();
ans-=q.top();q.pop();
}
printf("%.0lf",ans);
}
};
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
srand(time(0));
mine::main();
}

本文基于 知识共享署名-相同方式共享 4.0 国际许可协议发布
本文地址:http://zory.ink/posts/dcc7.html
转载请注明出处,谢谢!