• 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;
    }
  • 相关阅读:
    背景颜色的渐变设置--实现丰富多彩的背景效果
    CSS-sprit 雪碧图
    背景图片的相关设置
    关于阿里云图标的使用 iconfont
    HTML四种定位-粘滞定位
    HTML四种定位-固定定位
    HTML四种定位-绝对定位
    HTML四种常见的定位-相对定位
    水平居中
    CentOS8更换国内镜像源
  • 原文地址:https://www.cnblogs.com/shandongs1/p/9534632.html
Copyright © 2020-2023  润新知