zoukankan      html  css  js  c++  java
  • 洛谷 P3388 【模板】割点(割顶)

    传送门

    #include <bits/stdc++.h>
    
    using namespace std;
    using ll = long long;
    using p = pair<int, int>;
    const double pi(acos(-1));
    const int inf(0x3f3f3f3f);
    const int mod(1e9 + 7);
    const int maxn(2e4 + 10);
    const int maxm(2e5 + 10);
    int ecnt, head[maxn];
    int tim, dfn[maxn], low[maxn];
    int ccnt;
    bool cut[maxn];
    
    struct edge {
        int to, nxt;
    } edges[maxm];
    
    template<typename T = int>
    inline const T read()
    {
        T x = 0, f = 1;
        char ch = getchar();
        while (ch < '0' || ch > '9') {
            if (ch == '-') f = -1;
            ch = getchar();
        }
        while (ch >= '0' && ch <= '9') {
            x = (x << 3) + (x << 1) + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
    
    template<typename T>
    inline void write(T x, bool ln)
    {
        if (x < 0) {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x / 10, false);
        putchar(x % 10 + '0');
        if (ln) putchar(10);
    }
    
    void addEdge(int u, int v)
    {
        edges[ecnt].to = v;
        edges[ecnt].nxt = head[u];
        head[u] = ecnt++;
    }
    
    void tarjan(int cur, int pre)
    {
        int child = 0;
        dfn[cur] = low[cur] = ++tim;
        for (int i = head[cur]; compl i; i = edges[i].nxt) {
            int nxt = edges[i].to;
            if (not dfn[nxt]) {
                ++child;
                tarjan(nxt, cur);
                low[cur] = min(low[cur], low[nxt]);
                if (pre not_eq cur and low[nxt] >= dfn[cur] and not cut[cur]) {
                    ++ccnt;
                    cut[cur] = true;
                }
            } else if (nxt not_eq pre) {
                low[cur] = min(low[cur], dfn[nxt]);
            }
        }
        if (pre == cur and child >= 2) {
            ++ccnt;
            cut[cur] = true;
        }
    }
    
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("input.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        memset(head, -1, sizeof head);
        int n = read(), m = read();
        while (m--) {
            int u = read(), v = read();
            addEdge(u, v);
            addEdge(v, u);
        }
        for (int i = 1; i <= n; ++i) {
            if (not dfn[i]) {
                tarjan(i, i);
            }
        }
        write(ccnt, true);
        for (int i = 1; i <= n; ++i) {
            if (cut[i]) {
                write(i, false);
                putchar(32);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    Cmder安装和设置
    php7.x版本的新特性
    【Luogu】P4916 [MtOI2018]魔力环 题解
    Codeforces 1530E Minimax 题解
    昭阳E42-80 屏幕不亮,风扇狂转
    iPad宽高像素值
    关于UIView的autoresizingMask属性的研究
    判断单链表中是否存在环及查找环的入口点
    网络编程
    事件响应者链的工作原理
  • 原文地址:https://www.cnblogs.com/singularity2u/p/13922366.html
Copyright © 2011-2022 走看看