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. 为WebSphere Application Server v8.5安装并配置JDK7

    IBM WebSphere Application Server v8.5可以同时支持不同版本的JDK共存,并且可以通过命令设置概要文件所使用的JDK版本.WAS8.5默认安装JDK6,如果要使用JD ...

  2. 重新学习Java——Java基本的程序设计结构(二)

    上一节简单回顾了Java基本的一些程序设计的知识,这一节将继续根据<Java核心技术>这本书,进行这方面知识的复习与探索. 1. 字符串 Java字符串实际上就是Unicode字符序列.例 ...

  3. [ Nowcoder Contest 167 #C ] 部分和

    \(\\\) \(Description\) 给出一个长度为\(N\)的数组\(A[i]\),保证\(N\)为 \(2\) 的整次幂. 对于每个 \(i\ (i\in [0,N))\)求所有满足\(( ...

  4. BZOJ1499: [NOI2005]瑰丽华尔兹(dp)

    Description 你跳过华尔兹吗?当音乐响起,当你随着旋律滑动舞步,是不是有一种漫步仙境的惬意?众所周知,跳华尔兹时,最重要的是有好的音乐.但是很少有几个人知道,世界上最伟大的钢琴家一生都漂泊在 ...

  5. Meta标签 h5

    一  PC端meta标签 1 页面关键词 <meta name="keywords" content="your tags"> 2 页面描述 < ...

  6. [Android]异常3-java.lang.NoClassDefFoundError: javax.activation.DataHandler

    背景:JavaMail发送电子邮件 异常原因: 可能一>缺少DataHandler类相关jar包 可能二>有DataHandler类,DataHandler类与使用的mail.jar包不一 ...

  7. 没搞错吧,我只是个web前端工程师,不是manager,也不是leader...

    那个时候,我只想好好的学习web前端技术,恨不得把有限的时间和精力都放在提升技术上. 然而,让自己在坑里茁壮成长,要先适应坑内的环境. 首当其冲我们要弄明白的事情有: 团队成员的技术能力和状态 Lea ...

  8. CAD如何动态绘制带面积周长的圆?

    CAD绘制图像的过程中,画圆的情况是非常常见的,用户可以在控件视区点取任意一点做为圆心,再动态点取半径绘制圆. 主要用到函数说明: _DMxDrawX::DrawCircle 绘制一个圆.详细说明如下 ...

  9. Queueingconsumer 找不到

    springboot从1.5.9升级到2.0.0,queueingconsumer报错没有这个类,改为使用 DefaultConsumer

  10. 14mysql事务、数据库连接池、Tomcat

    14mysql事务.数据库连接池.Tomcat-2018/07/26 1.mysql事务 事务指逻辑上的一组操作,组成这组操作的各个单元,要么全部成功,要么全部不成功. MySQL手动控制事务 开启事 ...