ACM TJU 1556

Background

Consider the two networks shown below. Assuming that data moves around these
networks only between directly connected nodes on a peer-to-peer basis, a failure
of a single node, 3, in the network on the left would prevent some of the still
available nodes from communicating with each other. Nodes 1 and 2 could still
communicate with each other as could nodes 4 and 5, but communication between
any other pairs of nodes would no longer be possible.

Node 3 is therefore a Single Point of Failure (SPF) for this network. Strictly,
an SPF will be defined as any node that, if unavailable, would prevent at least
one pair of available nodes from being able to communicate on what was previously
a fully connected network. Note that the network on the right has no such node;
there is no SPF in the network. At least two machines must fail before there
are any pairs of available nodes which cannot communicate.

Input

The input will contain the description of several networks. A network description
will consist of pairs of integers, one pair per line, that identify connected
nodes. Ordering of the pairs is irrelevant; 1 2 and 2 1 specify the same connection.
All node numbers will range from 1 to 1000. A line containing a single zero
ends the list of connected nodes. An empty network description flags the end
of the input. Blank lines in the input file should be ignored.

Output

For each network in the input, you will output its number in the file, followed
by a list of any SPF nodes that exist.

The first network in the file should be identified as "Network #1", the second
as "Network #2", etc. For each SPF node, output a line, formatted as shown in
the examples below, that identifies the node and the number of fully connected
subnets that remain when that node fails. If the network has no SPF nodes, simply
output the text "No SPF nodes" instead of a list of SPF nodes.

Sample Input

1 2
5 4
3 1
3 2
3 4
3 5
0

1 2
2 3
3 4
4 5
5 1
0

1 2
2 3
3 4
4 6
6 3
2 5
5 1
0

0

Sample Output

Network #1
  SPF node 3 leaves 2 subnets

Network #2
  No SPF nodes

Network #3
  SPF node 2 leaves 2 subnets
  SPF node 3 leaves 2 subnets-----------------------------------------------------------------------------------------------------------手动分割线-------------------------------------------------------------------------------------------------------------------------题目大意:  给定一个有N点的无向连通图,问图中有哪些点去掉后图讲不在联通?同时输出去掉这个点后,图被分为几个联通块。  输入包含多组数据,每组以0结尾,每行描述图中边的两个顶点编号。每组数据中间有一个空行。  

思路:就是一边找割点,一边求联通分量啦......代码送上:
 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<string.h>
 4 using namespace std;
 5 #define N 1010
 6 int low[N],dfn[N],sub[N],n,m,cnt,e[N][N],vis[N],son;
 7 void init()
 8 {
 9     memset(vis,0,sizeof(vis));
10     low[1]=dfn[1]=1;
11     cnt=1;
12     son=0;
13     vis[1]=1;
14     memset(sub,0,sizeof(sub));
15 }
16 void dfs(int u)
17 {
18     for(int v=1;v<=n;v++)
19     {
20         if(!e[u][v])continue;
21         e[v][u]=e[u][v]=0;
22         if(!vis[v])
23         {
24             vis[v]=1;
25             cnt++;
26             dfn[v]=low[v]=cnt;
27             dfs(v);
28             if(low[u]>low[v]) low[u]=low[v];
29             if(low[v]>=dfn[u])
30             {
31                 if(u!=1) sub[u]++;
32                 else son++;
33             }
34         }
35         else if(low[u]>dfn[v])low[u]=dfn[v];
36     }
37 }
38 int main()
39 {
40     int u,v;
41     int num=1;
42     while(scanf("%d",&u),u)
43     {
44         memset(e,0,sizeof(e));
45         n=0;
46         scanf("%d",&v);
47         n=max(n,u);
48         n=max(n,v);
49         e[u][v]=1;
50         e[v][u]=1;
51         while(scanf("%d",&u),u)
52         {
53             scanf("%d",&v);
54             n=max(n,u);
55             n=max(n,v);
56             e[u][v]=1;
57             e[v][u]=1;
58         }
59         init();
60         dfs(1);
61
62         if(son>1)sub[1]=son-1;
63         int flag=0;
64         if(num>1)puts("");
65         printf("Network #%d\n",num++);
66         for(int i=1;i<=n;i++)
67         {
68             if(sub[i])
69             {
70                 flag=1;
71                 printf("  SPF node %d leaves %d subnets\n",i,sub[i]+1);
72             }
73         }
74         if(!flag)printf("  No SPF nodes\n");
75     }
76     return 0;
77 }
				
时间: 2024-10-07 02:07:11

ACM TJU 1556的相关文章

程序员常识--OJ系统及ACM测试题库大全

OJ是Online Judge系统的简称,用来在线检测程序源代码的正确性.著名的OJ有RQNOJ.URAL等.国内著名的题库有北京大学题库.浙江大学题库等.国外的题库包括乌拉尔大学.瓦拉杜利德大学题库等. 简介: Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交程序多种程序(如C.C++)源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性. 程序: 一个用户提交的程序在Online Judge系统下执行时将受到比较严格的限制,包括运

acm

http://www.acmerblog.com/杭电OJ系统(杭州电子科技大学在线判题系统):http://acm.hdu.edu.cn/ZOJ(浙江大学OJ):http://acm.zju.edu.cn/JOJ(吉林大学OJ):http://acm.jlu.edu.cn/厦门大学OJ:http://acm.xmu.edu.cn/POJ(北京大学OJ):http://poj.org/南开大学OJ:http://acm.nankai.edu.cn/TOJ(天津大学OJ):http://acm.t

程序猿常识--OJ系统和ACM测试考试大全

OJ它是Online Judge缩写系统,来在线检測程序源码的正确性. 著名的OJ有RQNOJ.URAL等. 国内著名的题库有北京大学题库.浙江大学题库等. 国外的题库包含乌拉尔大学.瓦拉杜利德大学题库等. 简单介绍: Online Judge系统(简称OJ)是一个在线的判题系统.用户能够在线提交程序多种程序(如C.C++)源码,系统对源码进行编译和运行,并通过预先设计的測试数据来检验程序源码的正确性. 程序: 一个用户提交的程序在Online Judge系统下运行时将受到比較严格的限制,包含运

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

ACM博客汇总及各大OJ

ACM-ICPC世界网站 http://acm.timus.ru http://acm.sgu.ru http://acm.hnu.cn http://acm.hdu.edu.cn http://acm.pku.edu.cn http://acm.zju.edu.cn http://acm.jlu.edu.cn http://acm.hnu.edu.cn http://acm.hit.edu.cn http://acm.whu.edu.cn http://acm.tju.edu.cn http:

ACM刷题常用链接

武汉科技大学  http://acm.wust.edu.cn/ 华中科技大学 http://acm.hust.edu.cn/vjudge/toIndex.action 杭州电子科技大学  http://acm.hdu.edu.cn/listproblem.php?vol=1 北京大学  http://poj.org/ 浙江大学 http://acm.zju.edu.cn/onlinejudge/showProblemsets.do 湖南大学 http://acm.hnu.cn/ RQNOJ ht

(转载)ACM训练计划,先过一遍基础再按此拼搏吧!!!!

ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. USACO http://ace.delos.com/usacogate 美国著名在线题库,专门为信息学竞赛选手准备 TJU http://acm.tongji.edu.cn/ 同济大学在线题库,唯一的中文题库,适合NOIP选手 ZJU http://acm.zju.edu.cn/ 浙江大学在线题库 JLU htt

ACM 入门计划

acm 本文由swellspirit贡献 ACM • I can accept failure. but I can't accept not trying. Life is often compared to a marathon, but I think it is more like being a sprinter; long stretches of hard work punctuated by brief moments in which we are given the oppo

TOJ 2850 Corn Fields 状压dp

Source: http://acm.tju.edu.cn/toj/showp.php?pid=2850 题意:n*m的土地上种东西,每个位置分为可以种和不能,种的方案要求不能相邻地种,问合法方案数.(写得有点乱) 分析:做过炮兵阵地,这题就是秒杀了. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 const int mo = 1000000