题面(权限题就不放题面了)
题解
三元环模板题,按题意模拟即可。
#include <cstdio>
#include <cstring>
#include <vector>
using std::vector;
const int N = 1e5 + 10, M = 2.5e5 + 10;
int n, m, a[N], deg[N], u[M], v[M], vis[N], tmp;
long long ans;
vector<int> to[N];
inline void swap(int &a, int &b) { tmp = a, a = b, b = tmp; }
inline int max(int a, int b) { return a > b ? a : b; }
inline int read() {
int ret = 0; char ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
while(ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
return ret;
}
int main () {
n = read(), m = read();
for(int i = 1; i <= n; ++i) a[i] = read();
for(int i = 1; i <= m; ++i) u[i] = read(), v[i] = read(), ++deg[u[i]], ++deg[v[i]];
for(int i = 1; i <= m; ++i) {
if(deg[u[i]] < deg[v[i]] || (deg[u[i]] == deg[v[i]] && u[i] > v[i])) swap(u[i], v[i]);
to[u[i]].push_back(v[i]);
}
for(int i = 1; i <= n; ++i) {
for(auto j : to[i]) vis[j] = i;
for(auto j : to[i])
for(auto k : to[j]) {
if(vis[k] == i) ans += max(max(a[i], a[j]), a[k]);
}
} printf("%lld
", ans);
return 0;
}