标签:getch swap long stream pre node name main iostream
统计三元环
很多代码在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; }
标签:getch swap long stream pre node name main iostream
原文地址:https://www.cnblogs.com/shandongs1/p/9534632.html