poj 1144 Network(割点 入门)
Network
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10907 Accepted: 5042 Description
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 file 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 file 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
0Sample Output
1
2Hint
You need to determine the end of one line.In order to make it's easy to determine,there are no extra blank before the end of each line.Source
模板~
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int MAXN = ;
const int MAXM = ;
struct Edge
{
int to,next;
bool cut;
} edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
bool Instack[MAXN],cut[MAXN];
int bridge,add_block[MAXN]; void addedge(int u,int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
}
void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for(int i = head[u]; i != -; i = edge[i].next)
{
v = edge[i].to;
if(v == pre)
continue;
if( !DFN[v] )
{
son++;
Tarjan(v,u);
if(Low[u] > Low[v]) Low[u] = Low[v]; if(Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i^].cut = true;
} if(u != pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if(Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if(u == pre && son > ) cut[u] = true;
if(u == pre) add_block[u] = son -;
Instack[u] = false;
top--;
}
void solve(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = bridge = ;
for(int i = ; i <= N; i++)
if( !DFN[i])
Tarjan(i,i);
int ans = ;
for(int i = ; i <= N; i++)
if(cut[i])
ans++;
printf("%d\n",ans);
}
void init()
{
tot = ;
memset(head,-,sizeof(head));
}
int main(void)
{
int n;
int maze[][];
while(scanf("%d",&n),n)
{
char ss[];
init();
memset(maze,,sizeof(maze));
getchar();
while(cin.getline(ss,),ss[] != '')
{
int u = ,cur = ,l = (int)strlen(ss);
while(ss[cur] != ' ' && cur < l)
{
u*= ;
u += ss[cur] - '';
cur++;
}
int v;
while(ss[cur] && cur < l)
{
v = ;
while(ss[cur] != ' ' && cur < l)
{
v*= ;
v += ss[cur] - '';
cur++;
}
maze[u][v] = maze[v][u] = ;
cur++;
}
}
for(int i = ; i <= n; i++)
for(int j = ; j < i; j++)
if(maze[i][j])
{
addedge(i,j);
addedge(j,i);
}
solve(n);
}
return ;
}
poj 1144 Network(割点 入门)的更多相关文章
- poj 1144 Network(割点)
题目链接: http://poj.org/problem?id=1144 思路分析:该问题要求求出无向联通图中的割点数目,使用Tarjan算法即可求出无向联通图中的所有的割点,算法复杂度为O(|V| ...
- POJ 1144 Network(无向图连通分量求割点)
题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...
- poj 1144 Network(无向图求割顶数)
题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...
- poj 1144 Network【双连通分量求割点总数】
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11042 Accepted: 5100 Descript ...
- POJ 1144 Network(tarjan 求割点个数)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17016 Accepted: 7635 Descript ...
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
随机推荐
- Android开发 LevelListDrawable详解
前言 此篇博客正在施工中... 作者其实就是想挖个坑备忘一下... 十分抱歉, 可以参考https://www.jianshu.com/p/f9ec65241b6b
- python 简单的图片比较
# by movie on 2019/12/18 from PIL import Image from PIL import ImageChops path1 = 'images/trumpA689. ...
- 基础回顾: 关于Session的一些细节
1 session是服务端技术, cookie是客户端技术 2 默认情况下, 一个浏览器独占一个session对象, 也就是说, 开启两个浏览器进程, 它们之间使用的session不是同一个sessi ...
- IDA*算法——骑士精神
例题 骑士精神 Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士, 且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐标相差为1,纵坐标相差为2或者 ...
- day07 linux磁盘分区,ps,kill,df,top命令使用
day07进入单用户模式删除密码不能进入系统问题: SELINUX=disabled 操作系统linux开机流程加电BIOS找到启动介质先读取第一个扇区(MBR)grup找到kernel加载到内存执行 ...
- LUOGU P4281 [AHOI2008]紧急集合 / 聚会 (lca)
传送门 解题思路 可以通过手玩或打表发现,其实要选的点一定是他们三个两两配对后其中一对的$lca$上,那么就直接算出来所有的$lca$,比较大小就行了. #include<iostream> ...
- dvajs+antd定制主题踩坑记录
记一下刚刚解决的问题,困扰了几周,期间困兽争斗,甚至想放弃antd组件库.终于出来了,人类科技又进步了(才怪). 首先我按照dva官网建立了项目.里面引入antd的各种组件,因为需要用到一个switc ...
- 国内有哪些质量高的JAVA社区?
国内有哪些质量高的JAVA社区? 转自:http://www.zhihu.com/question/29836842#answer-13737722 并发编程网 - ifeve.com 强烈推荐 Im ...
- #、%和$符号在OGNL表达式中的作用
#.%和$符号在OGNL表达式中经常出现,而这三种符号也是开发者不容易掌握和理解的部分.在这里笔者简单介绍它们的相应用途. 1.#符号的用途一般有三种. 1)访问非根对象属性,例如示例中的#ses ...
- java多线程编程建议
多线程编程建议 1,将应用设计成支持多线程并发,可提高性能 2,编写多线程程序,首先保证它是正确的,其次再考虑性能 3,同步处理的开销大于非同步处理,如果可能,尽量使用非同步处理 4,避免多个共享变量 ...