zoukankan      html  css  js  c++  java
  • Network (poj1144)

    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.
    无向图求割顶;
    模板题;
     1 #include<iostream>
     2 #include<string.h>
     3 #include<algorithm>
     4 #include<queue>
     5 #include<math.h>
     6 #include<stdlib.h>
     7 #include<stack>
     8 #include<stdio.h>
     9 #include<ctype.h>
    10 #include<map>
    11 #include<vector>
    12 using namespace std;
    13 vector<int>vec[1000];
    14 char ans[10000];
    15 bool flag[10000];
    16 int pre[1000];
    17 int low[1000];
    18 int tr[1000];
    19 int sizee = 0;
    20 int dfs(int u,int fa);
    21 int main(void)
    22 {
    23     int n;
    24     while(scanf("%d",&n),n!=0)
    25     {
    26         sizee = 0;
    27         int t;
    28         memset(flag,0,sizeof(flag));
    29         memset(pre,0,sizeof(pre));
    30         memset(low,0,sizeof(low));
    31         memset(tr,0,sizeof(tr));
    32         for(int i = 0; i < 1000; i++)
    33             vec[i].clear();
    34         while(scanf("%d",&t),t!=0)
    35         {
    36             int i,j;
    37             int id;
    38             gets(ans);
    39             int  l = strlen(ans);
    40             int sum = 0;
    41             for(i = 0; i <= l; )
    42             {
    43                 if(ans[i]>='0'&&ans[i]<='9')
    44                 {
    45                     sum = 0;
    46                     for(j = i; ans[j]!=' '&&ans[j]!=''&&j <= l; j++)
    47                     {
    48                         sum = sum*10;
    49                         sum+=ans[j]-'0';
    50                     }
    51                     i = j;
    52                     vec[t].push_back(sum);
    53                     vec[sum].push_back(t);
    54                 }
    55                 else i++;
    56             }
    57         }
    58         dfs(1,-1);
    59         int sum = 0;
    60         for(int i = 1; i <= n; i++)
    61         {
    62             sum+=tr[i];
    63         }
    64         printf("%d
    ",sum);
    65     }
    66     return 0;
    67 }
    68 int dfs(int u,int fa)
    69 {
    70     pre[u] = low[u] = ++sizee;
    71     int child = 0;
    72     for(int i = 0; i < vec[u].size(); i++)
    73     {
    74         int ic  = vec[u][i];
    75         if(!pre[ic])
    76         {
    77             child++;
    78             int lowv = dfs(ic,u);
    79             low[u] = min(low[u],lowv);
    80             if(lowv >= pre[u])
    81             {
    82                 tr[u] = 1;
    83             }
    84         }
    85         else if(pre[ic] < pre[u]&&ic!=fa)
    86         {
    87             low[u] = min(low[u],pre[ic]);
    88         }
    89     }
    90     if(fa < 0&& child == 1)tr[u] = 0;
    91     return low[u];
    92 }
  • 相关阅读:
    mongodb压缩——snappy、zlib块压缩,btree索引前缀压缩
    python cassandra 创建space table并写入和查询数据
    机器学习算法选择——特征提取
    机器学习的算法选择
    公积金联名卡——提取公积金用,用身份证即可办理
    Facebook图片存储系统Haystack——存小文件,本质上是将多个小文件合并为一个大文件来降低io次数,meta data里存偏移量
    HDFS namenode 高可用(HA)搭建指南 QJM方式 ——本质是多个namenode选举master,用paxos实现一致性
    javascript语言精粹:继承
    转:Javascript的10个设计缺陷
    转:CSS选择器笔记
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/6194273.html
Copyright © 2011-2022 走看看