bzoj 3498
Posted shandongs1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj 3498相关的知识,希望对你有一定的参考价值。
统计三元环
很多代码在bzoj都T诶
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <string> #define gc getchar() inline int read() {int x = 0, f = 1; char c = gc; while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = gc;} while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = gc; return x;} #undef gc using namespace std; const int N = 1e5 + 10, M = 2e5 + 5e4 + 10; int n, m; int A[M], B[M], W[N]; int du[N]; int vis[N]; int cnt, head[N]; struct Node {int v, nxt;} G[M]; inline void Add(int u, int v) {G[++ cnt].v = v, G[cnt].nxt = head[u], head[u] = cnt;} inline int Max(int a, int b) {if(a > b) return a; return b;} int main() { n = read(), m = read(); for(int i = 1; i <= n; i ++) W[i] = read(); for(int i = 1; i <= m; i ++) { A[i] = read(), B[i] = read(); du[A[i]] ++, du[B[i]] ++; } for(int i = 1; i <= n; i ++) head[i] = -1; for(int i = 1; i <= m; i ++) { if(du[A[i]] > du[B[i]] || (du[A[i]] == du[B[i]] && A[i] > B[i])) swap(A[i], B[i]); Add(A[i], B[i]); } long long Answer = 0; for(int k = 1; k <= m; k ++) { for(int i = head[A[k]]; ~ i; i = G[i].nxt) { vis[G[i].v] = k; } for(int i = head[B[k]]; ~ i; i = G[i].nxt) { if(G[i].v != A[k] && vis[G[i].v] == k) { Answer += Max(Max(W[A[k]], W[B[k]]), W[G[i].v]); } } } printf("%lld", Answer); return 0; }
以上是关于bzoj 3498的主要内容,如果未能解决你的问题,请参考以下文章