poj1144 求不同割点的个数
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11914 | Accepted: 5519 |
Description
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
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;
Output
Sample Input
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
2
/*
* Author: sweat123
* Created Time: 2016/6/20 21:01:10
* File Name: main.cpp
*/
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
struct node{
int to;
int next;
}edge[MAXN*MAXN];
int pre[MAXN],vis[MAXN],ind,n,ans;
int dfn[MAXN],low[MAXN];
void add(int x,int y){
edge[ind].to = y;
edge[ind].next = pre[x];
pre[x] = ind ++;
}
void dfs(int rt,int k){
dfn[rt] = k;
low[rt] = k;
for(int i = pre[rt]; i != -; i = edge[i].next){
int t = edge[i].to;
if(!dfn[t]){
dfs(t,k+);
low[rt] = min(low[t],low[rt]);
if(low[t] >= dfn[rt]){
vis[rt] ++;
}
}
else {
low[rt] = min(low[rt],dfn[t]);
}
}
}
int main(){
while(~scanf("%d",&n)){
if(!n)break;
ind = ;
memset(pre,-,sizeof(pre));
while(){
int x,y;
scanf("%d",&x);
if(!x)break;
while(){
scanf("%d",&y);
add(x,y);
add(y,x);
if(getchar() == '\n')break;
}
}
memset(vis,,sizeof(vis));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
dfs(,);
int ans = ;
vis[] --;
for(int i = ; i <= n; i++){
if(vis[i] > )ans += ;
}
printf("%d\n",ans);
}
return ;
}
poj1144 求不同割点的个数的更多相关文章
- poj 1523Tarjan算法的含义——求取割点可以分出的连通分量的个数
poj 1523Tarjan算法的含义——求取割点可以分出的连通分量的个数 题目大意:如题目所示 给你一些关系图——连通图,想要问你有没有个节点,损坏后,可以生成几个互相独立的网络(也就是连通分量), ...
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...
- UVA - 315 Network(tarjan求割点的个数)
题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第 ...
- tarjan求割边割点
tarjan求割边割点 内容及代码来自http://m.blog.csdn.net/article/details?id=51984469 割边:在连通图中,删除了连通图的某条边后,图不再连通.这样的 ...
- [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
- 一种快速求fibonacci第n个数的算法
利用动态规则的思路,摒弃传统的递归做法,可以得到一种快速的求fibonacci第n个数的算法: ''' 求第n(从1开始)位fibonacci数 fibonacci数列前两位为0, 1. 后面每一位数 ...
- 【剑指offer】求逆序对的个数
2013-09-07 10:50:31 面试题36:在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字构成一个逆序对.输入一个数组,求出这个数组中逆序对的总数. 小结: 最直观的的方法是: ...
- 求集合中选一个数与当前值进行位运算的max
求集合中选一个数与当前值进行位运算的max 这是一个听来的神仙东西. 先确定一下值域把,大概\(2^{16}\),再大点也可以,但是这里就只是写写,所以无所谓啦. 我们先看看如果暴力求怎么做,位运算需 ...
- LeetCode 29 Divide Two Integers (不使用乘法,除法,求模计算两个数的除法)
题目链接: https://leetcode.com/problems/divide-two-integers/?tab=Description Problem :不使用乘法,除法,求模计算两个数 ...
随机推荐
- 创建简单的机器人模型smartcar
前面我们使用的是已有的机器人模型进行仿真,这一节我们将建立一个简单的智能车机器人 smartcar,为后面建立复杂机器人打下基础. 一.创建硬件描述包. cd ~/catkin_ws/srcroscr ...
- 史上最全的CSS hack方式一览
做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来达到大家要求的页面表现.我个人是不太推荐使用hack的,要知道 ...
- 如何迁移Alwayson AG
Windows cluster要求同一个cluster中的所有windows版本都是相同的,这样就出现一个问题,当我们要将对windows进行升级时,(例如从windows 2008 R2升级到win ...
- Inline Workers--Web workers without a separate Javascript file
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </head&g ...
- linux磁盘分区-系统安装
零 系统下载: https://lists.centos.org/pipermail/centos-announce/2016-May/021895.html 往下拉可以看到 一 系统安装 1, 2, ...
- Linux Linux下特殊的printf函数和fputs函数
Linux下,printf函数必须以'\n'结尾才会立刻输出到屏幕,如果没有'\n'直到输出缓冲区满了以后才会打印到屏幕上(敲击换行也算),如果需要不换行的输出,一般可以使用write函数代替.'\n ...
- 关于onbeforeunload的一些想法
页面在关闭前会有onbeforeUnload事件,来询问用户是否要关闭这个页面OR选项卡 浏览器的F5刷新为按下F5----onbeforeUnload----onunload----onload; ...
- css一些记录
比如右侧链接:更多 ,定义此span float:right ,但是 更多 要写在 短标题的左边 比如:<span>更多</span> <font>这是短标题 ...
- 数据库Mark.2
select count(*) as count,DATE_SUB('2016-10-04',INTERVAL regDay DAY) from result_1005 group by DATE_S ...
- hadoop:将WordCount打包成独立运行的jar包
hadoop示例中的WordCount程序,很多教程上都是推荐以下二种运行方式: 1.将生成的jar包,复制到hadoop集群中的节点,然后运行 $HADOOP_HOME/bin/hadoop xxx ...