[题目链接]
https://codeforces.com/contest/437/problem/C
[算法]
按照点的权值从小到大删点为最优策略
每条边对答案的贡献为两个端点权值的最小值
时间复杂度 : O(N + M)
[代码]
#include<bits/stdc++.h> using namespace std; #define MAXN 1010 int a[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); } template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); } template <typename T> inline void read(T &x) { T f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= f; } int main() { int n , m , ans = 0; read(n); read(m); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= m; i++) { int x , y; read(x); read(y); ans += min(a[x],a[y]); } printf("%d ",ans); return 0; }