zoukankan      html  css  js  c++  java
  • luogu P5058 [ZJOI2004]嗅探器 割点

    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    typedef unsigned long long ULL;
    const int N = 5e5+10, M = 5e5+10;
    int n, m;
    int h[N], e[M], ne[M], idx;
    int dfn[N], low[N], timestamp;
    int stk[N], top;
    int dcc_cnt;
    //存每个双连通分量里有哪些点
    vector<int> dcc[N];
    //每个点是不是割点
    bool cut[N];
    //特判根节点
    int root;
    int a,b;
    void add(int a, int b)
    {
        e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
    }
    void tarjan(int u)
    {
        dfn[u] = low[u] = ++ timestamp;
        for (int i = h[u]; ~i; i = ne[i])
        {
            int j = e[i];
            //如果没被遍历过
            if (!dfn[j])
            {
                tarjan(j);
                low[u] = min(low[u], low[j]);
                //                            表示b在j的子树中,就找到了
                if (dfn[u] <= low[j]&&u!=a&&dfn[b]>=dfn[j])
                {
                    cut[u] = true;
                    return ;
                }
            }
            else
                low[u] = min(low[u], dfn[j]);
        }
    }
    
    int main()
    {
        idx = n = timestamp = top = dcc_cnt = 0;
        memset(h, -1, sizeof h);
        memset(dfn, 0, sizeof dfn);
        memset(cut, 0, sizeof cut);
        cin>>n;
        while (cin>>a>>b)
        {
            if(a==0&&b==0)
                break;
            add(a, b), add(b, a);
        }
        cin>>a>>b;
        //以a为根
        tarjan(a);
        for(int i=1; i<=n; i++)
            if(cut[i])
            {
                cout<<i<<endl;
                return 0;
            }
        puts("No solution");
        return 0;
    }
  • 相关阅读:
    UWP AppConnection.
    Qt 多线程使用moveToThread
    C#综合细说进程、应用程序域与上下文
    C++ std::function
    商品价格加价区间的实现(策略模式)
    学习web前端三个月感悟
    triangle leetcode C++
    Linux入门视频
    轻松学习Linux之进程监视与管理
    阻止缓冲区溢出攻击
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12933260.html
Copyright © 2011-2022 走看看