zoukankan      html  css  js  c++  java
  • POJ 1144 Network (求割点)

    题意:

    给定一幅无向图, 求出图的割点。

    割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html

    分析:

    输入有点麻烦, 用stringsteam 会比较简单

    #include<cstdio>
    #include<iostream>
    #include<queue>
    #include<cstring>
    #include<string>
    #include<sstream>
    #include<map>
    #include<stack>
    #include<vector>
    #include<algorithm>
    #include<cmath>
    #define rep(i,a,b) for(int i = a; i < b; i++)
    #define _rep(i,a,b) for(int i = a; i <= b; i++)
    using namespace std;
    const int maxn = 107;
    vector<int> G[maxn];
    int n, Index, root, ans;
    int dfn[maxn], low[maxn], cut[maxn];
    void tarjan(int u, int father){
        dfn[u] = Index;
        low[u] = dfn[u];
        Index++;
        int child = 0;
        for(int i = 0; i < G[u].size(); i++){
            int v = G[u][i];
            if(!dfn[v]){
                child++;
                tarjan(v, u);
                low[u] = min(low[v], low[u]);
                if(low[v] >= dfn[u] && u != root) cut[u] = 1;
                if(u == root && child == 2) cut[u] = 1;
            }else if(v != father){
                low[u] = min(low[u], dfn[v]);
            }
        }
    }
    int main(){
        ios::sync_with_stdio(false);
        while(cin >> n && n){
            Index = 1;
            memset(dfn, 0, sizeof(dfn));
            memset(low, 0, sizeof(low));
            memset(cut, 0, sizeof(cut));
            _rep(i,1,n) G[i].clear();
            root = 1, ans = 0;
            string input;
            while(getline(cin, input)){
                if(input[0] == '0') break;
                stringstream ss(input);
                int u, v;
                ss >> u;
                while(ss >> v){
                    G[u].push_back(v);
                    G[v].push_back(u);
                }
            }
            tarjan(1,1);
            _rep(i,1,n) if(cut[i]) ans++;
            cout << ans << "
    ";
        }
        return 0;
    }
  • 相关阅读:
    用小百合学python
    驱动对象 设备对象 设备栈 乱杂谈
    [转]很经典的http协议详解
    利用VMWare和WinDbg调试驱动程序
    GCC基础
    史上最著名的10个思想实验 (转)
    windows XP下驱动开发环境设置(DDK+VC6.0)
    守护进程
    驱动SYS开发总结
    ASP.NET学习笔记1
  • 原文地址:https://www.cnblogs.com/Jadon97/p/8360184.html
Copyright © 2011-2022 走看看