The Child and Toy
time limit per test1 second
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
Input
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
input
4 3
10 20 30 40
1 4
1 2
2 3
output
40
input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
output
400
input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
output
160
就是给你n个点,每个点有个权值,然后你要把这些点都删掉,删一个点的代价是与这个点相连的未被删除的点的权值之和。。。
洗澡的时候顺便贪心了一下,从大到小就好了
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
struct lpl{
int num;
long long val;
}node[maxn];
vector<int> point[maxn];
int n, m;
long long ans, ld[maxn];
bool flag[maxn];
inline void putit()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) node[i].num = i, scanf("%lld", &node[i].val), ld[i] = node[i].val;
for(int a, b, i = 1; i <= m; ++i){
scanf("%d%d", &a, &b);
point[a].push_back(b); point[b].push_back(a);
}
}
inline bool cmp(lpl A, lpl B){return A.val > B.val;}
int main()
{
putit();
sort(node + 1, node + n + 1, cmp);
for(int i = 1; i <= n; ++i){
flag[node[i].num] = true;
for(int now, j = point[node[i].num].size() - 1; j >= 0; --j){
now = point[node[i].num][j]; if(flag[now]) continue;
ans += ld[now];
}
}
cout << ans;
return 0;
}