zoukankan      html  css  js  c++  java
  • Network

    Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    Description

    Download as PDF

    A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N. No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.

    Input

    The input file consists of several blocks of lines. Each block describes one network. In the first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which there is a direct line from this place. These at most N lines completely describe the network, i.e., each direct connection of two places in the network is contained at least in one row. All numbers in one line are separated by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0.

    Output

    The output contains for each block except the last in the input file one line containing the number of critical places.

    Sample Input

    5
    5 1 2 3 4
    0
    6
    2 1 3
    5 4 6 2
    0
    0

    Sample Output

    1
    2

    题目大意:
    给你一个无向图,求其中割点的个数目。
    输入数据
    第一行一个 n 代表有 n 个点
    接下来有多行,一直到读入一个 0,算整个地图的读入结束,再读入一个0,文件数据结束。
    每行有第一个数字a,代表接下来的数字都 和 a 相连。 
     
    知识汇总:
    割点:无向连通图中,如果删除某点后,图变成不连通了,则称该点为割点。
    这里割点 和 桥 都是无向图里的概念,大家在这里不要混淆了。
    求割点
    一个顶点u是割点,当且仅当满足(1)或(2)
    (1) u为树根,且u有多于一个子树。
    (2) u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的父亲),使得 dfn(u)<=low(v)。(也就是说 V 没办法绕过 u 点到达比 u dfn要小的点)
    注:这里所说的树是指,DFS下的搜索树。
     
    求割点 tarjan里 low  和  dfn
    dfn[u]定义和前面类似,但是low[u]定义为u
    或者u的子树中能够通过非父子边追溯到的
    最早的节点的DFS开始时间
    在Tarjan算法求割点我们要加一个数组 Father[u], 判断两者是否是父子边
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    
    #define N 110
    
    using namespace std;
    
    vector<vector<int> > G;
    
    int dfn[N], low[N], n, Time, f[N];
    
    void init()  //初始化
    {
        G.clear();    // G清0
        G.resize(n+1);  // 申请空间
    
        Time = 0;
        memset(dfn, 0, sizeof(dfn));
        memset(low, 0, sizeof(low));
        memset(f, 0, sizeof(f));
    }
    
    void Tarjan(int u, int fa)
    {
        low[u] = dfn[u] = ++Time;  // 求low, dfn
        f[u] = fa;
    
        int len = G[u].size(), v;
    
        for(int i = 0; i < len; i++)
        {
            v = G[u][i];
    
            if(!dfn[v])
            {
                Tarjan(v, u);
                low[u] = min(low[u], low[v]);  //low取最小的
            }
            else if(v != fa)
                low[u] = min(low[u], dfn[v]);   //low取最小的
        }
    }
    
    void slove()
    {
        int ans = 0, rootson = 0;
        int cnt[N] = {false};
    
        Tarjan(1, 0);
    
        for(int i = 2; i <= n; i++)
        {
            int v = f[i];
    
            if(v == 1)
                rootson++;
            else if(dfn[v] <= low[i])
                cnt[v] = true;   //是割点置为true
        }
    
        for(int i = 2; i <= n; i++)   //判断该点是否是割点
            if(cnt[i])
                ans++;
        if(rootson > 1)   //判断1点即根节点是不是割点
            ans++;
    
        printf("%d
    ", ans);
    }
    
    int main()
    {
        int a, b;
        char c;
    
        while(scanf("%d", &n), n)
        {
            init();
    
            while(scanf("%d", &a), a)
            {
                while(scanf("%d%c", &b, &c)) // 格式控制
                {
                    G[a].push_back(b);
                    G[b].push_back(a);
                    if(c == '
    ')
                        break;
                }
            }
            slove();
        }
        return 0;
    }
    让未来到来 让过去过去
  • 相关阅读:
    SSRF——和远程文件包含的区别在于远程文件包含多是包含攻击者的主机文件,SSRF是内网主机的文件
    SSRF中的绕过手段——字节总结得比较好,如何绕过SSRF的保护机制,DNS欺骗,使用IPV6地址,十六进制编码、八进制编码、双字编码、URL编码和混合编码等
    SSRF——服务端请求伪造,根因是file_get_contents,fsockopen,curl_exec函数调用,类似远程文件包含,不过是内网机器
    文件包含——本地文件包含和远程文件包含
    文件包含和目录遍历区别——目标都是信息泄露,但手段一个是利用函数来包含web目录以外的文件,另外一个是对web路径访问权限设置不严格导致
    DFS——单词分割,原来还是要使用cached dp才能避免不超时
    模块module间引用和使用本地maven库的jar包
    机器学习西瓜书白话解读笔记---0401-0404、信息和熵的度量
    机器学习实战笔记---0、读大纲
    心得体悟帖---201129(【社会规律】)
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4707009.html
Copyright © 2011-2022 走看看