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;
    }
  • 相关阅读:
    中断向量表
    内核进程的堆栈 [转]
    int指令理解
    Linux进程创建和结束
    Linux 信号signal处理机制
    wait和waitpid详解
    linux 如何清理僵尸进程
    API:System V & POSI
    shell
    Code POJ
  • 原文地址:https://www.cnblogs.com/Jadon97/p/8360184.html
Copyright © 2011-2022 走看看