zoj——1311 Network
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的更多相关文章
- ZOJ 2676 Network Wars[01分数规划]
ZOJ Problem Set - 2676 Network Wars Time Limit: 5 Seconds Memory Limit: 32768 KB Special J ...
- ZOJ 2676 Network Wars(最优比例最小割)
Network Wars Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge Network of Bytelan ...
- POJ 1459 && ZOJ 1734--Power Network【最大流dinic】
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25108 Accepted: 13077 D ...
- POJ 1861 & ZOJ 1542 Network(最小生成树之Krusal)
题目链接: PKU:http://poj.org/problem?id=1861 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- ZOJ QS Network
QS Network Time Limit: 2 Seconds Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...
- ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)
[题意]给出一个带权无向图,求割集,且割集的平均边权最小. [分析] 先尝试着用更一般的形式重新叙述本问题.设向量w表示边的权值,令向量c=(1, 1, 1, --, 1)表示选边的代价,于是原问题等 ...
- zoj 2676 Network Wars 0-1分数规划+最小割
题目详解出自 论文 Amber-最小割模型在信息学竞赛中的应用 题目大意: 给出一个带权无向图 G = (V,E), 每条边 e属于E都有一个权值We,求一个割边集C,使得该割边集的平均边权最小,即最 ...
- ZOJ 2676 Network Wars(网络流+分数规划)
传送门 题意:求无向图割集中平均边权最小的集合. 论文<最小割模型在信息学竞赛中的应用>原题. 分数规划.每一条边取上的代价为1. #include <bits/stdc++.h&g ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
随机推荐
- [AHOI2006] 文本编辑器editor
Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对"文本编辑器"做了一个抽象的定义: ...
- 2017青岛网络赛1011 A Cubic number and A Cubic Number
A Cubic number and A Cubic Number Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/3276 ...
- 暴力/思维 HDOJ 5386 Cover
题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...
- 用Movie显示gif(1)SimpleGif
代码如下: import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; ...
- jquery实现文字自动向上滚动,鼠标放上去停止,移开继续滚动代码...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- STL内存分配方式
关于STL用的很多比如map, vector, set, queue, stack等等.很少关注它的内存分配情况,但是经常遇到比如使用map,不停的在map中插入了一些很小的对象,然后释放了一些,然后 ...
- SpringMVC中Controller类的方法返回String不跳转,而是将字符串显示到页面
问题描述: 在spring中,控制层的注解一般都是使用@Controller,如果哪个请求参数需要返回数据的话,我们可以在该方法上配合@ResponseBody注解使用,这也是比较常见的方式了. 今天 ...
- 重构27-Remove God Classes(去掉神类)
在传统的代码库中,我们常常会看到一些违反了SRP原则的类.这些类通常以Utils或Manager结尾,有时也没有这么明显的特征而仅仅是普通的包含多个功能的类.这种God类还有一个特征,使用语句或注释将 ...
- 4星|《OKR工作法》:关注公司的真正目标,以周为单位做计划和考核
本书篇幅比较小,两个小时就可以看完.主要内容讲OKR工作法的基本概念,然后用一个虚拟的创业公司的创业故事来演示实施OKR过程中可能遇到的问题.OKR给创业带来的好处. OKR工作法相对来说是比较简单的 ...
- (独孤九剑)--cURL
[一]概论 日常开发里,cURL使用最多的协议就是HTTP协议的GET.POST请求,其他协议和请求方式用的较少. [二]开启 开发前检验是否开启了cURL模块,开启方法为php.int中打开exte ...