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. SQL数据库语言基础

    表的创建: 1.创建列(字段):列名+类型 2.设置主键列:能够唯一标识一条数据 3.设置唯一:内容不能重复 4.外键关系: 一张表(从表)其中的某列引用自另外一张表(主表)中的主键列 设计表: 数据 ...

  2. A8ERP权限管理系统

  3. leetcode692 Top K Frequent Words

    思路: 堆.实现: #include <bits/stdc++.h> using namespace std; class Solution { public: inline bool c ...

  4. Rxjava1升级Rxjava2踩坑一记

    Rxjava1升级Rxjava2坑 共存问题 通常情况下,如果我们希望在一个模块中既想使用rxjava1又想使用rxjava2,这个时候在运行的时候会出现一下报错: ... APK META/-INF ...

  5. Android APK瘦身之webp图片

    webp格式是谷歌推出的一种有损压缩格式,这种图片格式相比png或者jpg格式的图片损失的质量几乎可以忽略不计,但是压缩后图片的体积却比png或者jpg要小很多.亲测一个100kb的png图片经过we ...

  6. Windows 2008 防火墙开放端口

    当我们使用新服务器架设新主机时,经常会遇到网站无法访问的情况,当问及客服时,经常会告知,操作系统默认不打开80端口,请先确定80是否打开并确定没有被占用.那么,我们该如何打开80端口呢? 方法/步骤 ...

  7. IDEA中springboot项目打包成jar

      springboot的打包方式有很多种.有打成war的,有打成jar的,也有直接提交到github,通过jekins进行打包部署的.这里主要介绍如何打成jar进行部署.不推荐用war,因为spri ...

  8. 【转载】dubbo约束的引入(解决eclipse中报错问题)

    在采用分布式系统架构时,我们会经常使用到阿里巴巴的dubbo的分布式框架. 在相关xml配置了dubbo的约束依赖后,即使能上网eclipse.myeclipse等IDE也是无法识别dubbo的相关约 ...

  9. react 返回上一页

    import * as React from 'react' import { Layout } from 'antd'; import creatHistory from 'history/crea ...

  10. linux运行jar报错

    通过maven打jar包,然后复制到虚拟机上执行nohup java -jar xxx.jar &命令,运行jar文件,这时抛出了异常 com.mysql.jdbc.exceptions.jd ...