CF437C The Child and Toy 题解
Ryc12345678910 · · 题解
CF437C The Child and Toy 题解
题意
给出一个
题解
这个删点操作,等价于删边。每条边在最后都会被删除,所以我们把原来的求删点变成求删边。然后我们考虑到,一条边被删除时的边权取决于它的两个顶点。后面的策略就显然了,肯定让点权较小的那个点删掉这条边。
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline void solve() {
int n, m; cin >> n >> m;
vector<int> v(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> v[i];
ll ans = 0;
while (m--) {
int a, b; cin >> a >> b;
ans += min(v[a], v[b]);
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}