将边权平均分到两顶点,按点权从大到小取即可。这样的话如果某人取到两点则获得边权,否则对两人均无影响,并且最后每条边都会处于其中的一种情况。假装证明了正确性。
#include#include #include #include #include #include using namespace std;int read(){ int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') { if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f;}#define N 10010int n,m,a[N],ans;int main(){#ifndef ONLINE_JUDGE freopen("bzoj2563.in","r",stdin); freopen("bzoj2563.out","w",stdout); const char LL[]="%I64d\n";#else const char LL[]="%lld\n";#endif n=read(),m=read(); for (int i=1;i<=n;i++) a[i]=read()<<1; for (int i=1;i<=m;i++) { int x=read(),y=read(),z=read(); a[x]+=z,a[y]+=z; } sort(a+1,a+n+1);reverse(a+1,a+n+1); for (int i=1;i<=n;i++) if (i&1) ans+=a[i];else ans-=a[i]; cout<<(ans>>1); return 0;}