• 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;
    }
  • 相关阅读:
    面试笔试
    scala(9) Monad
    scala (8) 模糊匹配
    scala (7) Set and Tuple
    scala (6) Map
    scala (5) 可变序列和不可变序列
    scala (4) 可变数组和不可变数组
    scala (3) Function 和 Method
    scala (2) while 和变量
    scala (1) for 循环
  • 原文地址:https://www.cnblogs.com/Jadon97/p/8360184.html
Copyright © 2020-2023  润新知