1. 程式人生 > >luoguP4643 阿狸和桃子的挑戰 思維

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;
}