zoukankan      html  css  js  c++  java
  • poj 1144(割点)

    用了#include <sstream> 来处理前面的数据,太好用了

    其他的就是用类似tarjan的算法来求割点.

    Network
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 7537   Accepted: 3546

    Description

    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

    Hint

    You need to determine the end of one line.In order to make it's easy to determine,there are no extra blank before the end of each line.

    Source

    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <sstream>
    #include <iostream>
    using namespace std;
    #define N 110
    #define INF 0x3ffffff
    
    int n;
    char str[N];
    int g[N][N];
    int num;
    int low[N];
    
    void dfs(int s,int cnt)
    {
        low[s]=cnt;
        int mi=low[s];
        int k=0;
        for(int i=1;i<=n;i++)
        {
            if(g[s][i]==0||s==i) continue;
            if(low[i] == -1)
            {    
                dfs(i,cnt+1);
                if(low[i] >= cnt) k++;
            }
            mi=min(low[i],mi);
        }
        low[s]=mi;
        if(cnt==0) k--;
        if(k>0) num++;
    }
    
    int main()
    {
        while(scanf("%d",&n)&&n)
        {
            getchar();
            memset(g,0,sizeof(g));
            memset(low,-1,sizeof(low));
            num=0;
            while(gets(str)&&str[0]!='0')
            {
                stringstream in(str);
                int x,y;
                in >> x;
                while(in>>y)
                {
                    g[x][y]=g[y][x]=1;
                }
            }
            dfs(1,0);
            printf("%d\n",num);
        }
        return 0;
    }
  • 相关阅读:
    html调用hadoop WebHDFS REST API
    推荐相关
    Resources of Studying Hadoop
    远程调试Hadoop(转)
    MYSQL复制的几种模式
    Hadoop实战第四章读书笔记
    FMS3系列(七):FMS案例开发视频聊天室
    Flex与.NET互操作系列文章
    使用FluorineFx Silverlight库实现Silverlight远程过程调用(RPC)
    修改 MySQL帐号密码,增加新用户
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/3077229.html
Copyright © 2011-2022 走看看