luoguP4643 阿狸和桃子的挑战 思维


看下数据范围:

\(n \leq 14\),emmmm,状压\(dp\)的分

\(n \leq 10000, m \leq 100000\),emmmm.....???,这是什么数据范围?

再观察一下所求

点十分好控制,边非常不好控制

能不能把边转化为点呢?

把边给均分给两边的点?

诶,好像可以了.....

然后就没了.....


#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
	
#define gc getchar
inline int read() {
	int p = 0, w = 1; char c = gc();
	while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
	while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
	return p * w;
}

int n, m;
ll val[200050];

int main() {
	n = read(); m = read();
	rep(i, 1, n) val[i] = 2 * read();
	rep(i, 1, m) {
		int u = read(), v = read(), w = read();
		val[u] += w; val[v] += w;
	}
	sort(val + 1, val + n + 1);
	ll ans = 0;
	drep(i, n, 1) 
	if(!((n - i) & 1)) ans += val[i];
	else ans -= val[i];
	printf("%lld\n", ans / 2);
	return 0;
}

posted @ 2018-12-29 23:45  remoon  阅读(180)  评论(0编辑  收藏  举报