Network


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 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 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

题意:

电话公司(TLC)正在建立一个新的电话电缆网络。它们连接数个整数,从1到n,没有两个地方有相同的数字。这些线是双向的,总是连接在一起的两个地方,在每一个地方的电话线结束在交换机。每一个地方都有一个电话交换机。从每一个地方都可以通过其他地方的线,但它不需要直接连接,它可以通过几个交换。有时电源在一个地方故障,然后交换不工作。TLC的官员意识到,在这种情况下,除了失败的地方是不可到达的之外,也可能导致其他地方不能互相连接。在这种情况下,我们会说发生故障的地方是关键的。现在,官员们正试图编写一个程序来找出所有这些关键地点的数量。帮助他们。

思路:

裸题,tarjan求割点的数量

但是输入的时候特别恶心、、、

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 10010
using namespace std;
char ch[N];
int n,m,x,y,tim,tot,ans;
int dfn[N],low[N],vis[N],head[N],cut_point[N];
struct Edge
{
    int from,to,next;
}edge[N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
void add(int x,int y)
{
    tot++;
    edge[tot].to=y;
    edge[tot].next=head[x];
    head[x]=tot;
}
void clean()
{
    ans=,tim=;tot=;
    memset(dfn,,sizeof(dfn));
    memset(low,,sizeof(low));
    memset(vis,,sizeof(vis));
    memset(head,,sizeof(head));
    memset(cut_point,,sizeof(cut_point));
}
void tarjan(int now,int pre)
{
    ; bool boo=false; vis[now]=true;
    dfn[now]=low[now]=++tim;
    for(int i=head[now];i;i=edge[i].next)
    {
        int t=edge[i].to;
        )==i) continue;
        if(!dfn[t])
        {
            sum++;tarjan(t,i);
            low[now]=min(low[now],low[t]);
            if(low[t]>=dfn[now]) boo=true;
        }
        else low[now]=min(low[now],dfn[t]);
    }
    ) ans++;}
    else if(boo) ans++;
}
int main()
{
    )
    {
        n=read();) break;
        clean();
        while(scanf("%d",&x)&&x)
        {
            while(getchar()!='\n')
            {
                scanf("%d",&y);
                add(x,y),add(y,x);
            }
        }
        ;i<=n;i++)
         );
        printf("%d\n",ans);
    }
    ;
}

突然发现自己好zz啊,老是把东西写反、、、

zoj——1311 Network的更多相关文章

  1. ZOJ 2676 Network Wars[01分数规划]

    ZOJ Problem Set - 2676 Network Wars Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special J ...

  2. ZOJ 2676 Network Wars(最优比例最小割)

    Network Wars Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge Network of Bytelan ...

  3. POJ 1459 &amp;&amp; ZOJ 1734--Power Network【最大流dinic】

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 25108   Accepted: 13077 D ...

  4. POJ 1861 &amp; ZOJ 1542 Network(最小生成树之Krusal)

    题目链接: PKU:http://poj.org/problem?id=1861 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  5. ZOJ QS Network

    QS Network Time Limit: 2 Seconds      Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...

  6. ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)

    [题意]给出一个带权无向图,求割集,且割集的平均边权最小. [分析] 先尝试着用更一般的形式重新叙述本问题.设向量w表示边的权值,令向量c=(1, 1, 1, --, 1)表示选边的代价,于是原问题等 ...

  7. zoj 2676 Network Wars 0-1分数规划+最小割

    题目详解出自 论文 Amber-最小割模型在信息学竞赛中的应用 题目大意: 给出一个带权无向图 G = (V,E), 每条边 e属于E都有一个权值We,求一个割边集C,使得该割边集的平均边权最小,即最 ...

  8. ZOJ 2676 Network Wars(网络流+分数规划)

    传送门 题意:求无向图割集中平均边权最小的集合. 论文<最小割模型在信息学竞赛中的应用>原题. 分数规划.每一条边取上的代价为1. #include <bits/stdc++.h&g ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. GIT学习之路第三天 文件操作

    本文参考廖雪峰老师的博客进行总结,完整学习请转廖雪峰博客 一.版本回退 1.git log提交日志 在git中可以通过个git log 命令显示从最近到最远的提交日志. $ git log commi ...

  2. Linux用户、用户组权限管理详解

    Linux用户管理三个重要文件详解: Linux登陆需要用户名.密码./etc/passwd 文件保存用户名.登录Linux时,Linux 先查找 /etc/passwd 文件中是否有这个用户名,没有 ...

  3. js作用域、异步——学习笔记

    所有的 for if switch while do 等等,都属于块级作用域,里面声明的对象,外面也能访问.但function 函数里的作用域,在函数外是访问不到的. 但函数作用域里面可以访问外面. ...

  4. SQL传入时间获取到时间的周一和周日

    declare @time datetime declare @timeMonday datetime set @time='2013-11-07' ) ,@time) select @timeMon ...

  5. Listview多种布局的使用

    ListView中有两个可以用来让ListView可以在视图中显示多种布局的方法,分别是getItemType和getViewTypeCount 其中 getItemViewType返回的是有参数po ...

  6. js中获取class封装

    1.封装 //封装getClass function getClass(tagName,className) //获得标签名为tagName,类名className的元素 { if(document. ...

  7. 拒绝了对对象 'data'(数据库 'xxx',所有者 'dbo')的 SELECT 权限

    拒绝了对对象 'data'(数据库 'xxx',所有者 'dbo')的 SELECT 权限解决的方法:1>在数据库里相应的用户权限中,把db_denydatareader的复选框的勾去掉.很多初 ...

  8. Farseer.net轻量级开源框架 入门篇:Where条件的终极使用

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 查询数据详解 下一篇:Farseer.net轻量级开源框架 中级篇: 事务的使用 ...

  9. Shell printf命令

    Shell 的另一个输出命令 printf.默认 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n. #!/bin/bash printf "%-10s %-8s %- ...

  10. 梦想CAD控件COM接口自定义命令

    在CAD软件操作中,为方便使用者,使用自定义命令发出命令,完成CAD绘图,修改,保存等操作.点击此处下载演示实例. _DMxDrawX::RegistUserCustomCommand 向CAD控件注 ...