Bzoj 3498 Cakes(三元环)
Posted water-mi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Bzoj 3498 Cakes(三元环)相关的知识,希望对你有一定的参考价值。
题面(权限题就不放题面了huaji)
题解
三元环模板题,按题意模拟即可。
#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;
}
以上是关于Bzoj 3498 Cakes(三元环)的主要内容,如果未能解决你的问题,请参考以下文章
bzoj4232: [Neerc2011 Northern]Kids Like Cakes