【poj1144】 Network
http://poj.org/problem?id=1144 (题目链接)
题意
求无向图的割点。
Solution
Tarjan求割点裸题。并不知道这道题的输入是什么意思,也不知道有什么意义= =,欺负我英语不好是吗。。。
代码
// poj1144
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<set>
#define MOD 1000000007
#define inf 2147483640
#define LL long long
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline LL getint() {
LL x=0,f=1;char ch=getchar();
while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
} const int maxn=200;
struct edge {int to,next;}e[maxn<<2];
int head[maxn],p[maxn],dfn[maxn],low[maxn],f[maxn];
int cnt,root,n,ind; void link(int u,int v) {
e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;
e[++cnt].to=u;e[cnt].next=head[v];head[v]=cnt;
}
void Tarjan(int u,int fa) {
dfn[u]=low[u]=++ind;
f[u]=1;
for (int i=head[u];i;i=e[i].next) if (e[i].to!=fa) {
if (!f[e[i].to]) {
Tarjan(e[i].to,u);
low[u]=min(low[u],low[e[i].to]);
if (low[e[i].to]>=dfn[u] && u!=1) p[u]++;
else if (u==1) root++;
}
else low[u]=min(low[u],dfn[e[i].to]);
}
}
int main() {
while (scanf("%d",&n)!=EOF && n) {
for (int i=1;i<=n;i++) head[i]=low[i]=dfn[i]=f[i]=p[i]=0;
int u,v;cnt=root=ind=0;
while (scanf("%d",&u)!=EOF && u)
while (getchar()!='\n') {
scanf("%d",&v);
link(u,v);
}
Tarjan(1,0);
int ans=0;
if (root>1) ans++;
for (int i=2;i<=n;i++) if (p[i]) ans++;
printf("%d\n",ans);
}
return 0;
}
【poj1144】 Network的更多相关文章
- 【POJ1144】Network(割点)(模板)
题意:给定一张无向图,求割点个数 思路:感谢CC大神http://ccenjoyyourlife.blog.163.com/的讲解 割点的定义就是某个联通块中删去此点连通性发生变化的的点 有两种割点: ...
- 【BZOJ】【1834】【ZJOI2010】Network 网络扩容
网络流/费用流 这题……我一开始sb了. 第一问简单的最大流…… 第二问是要建费用流的图的……但是是在第一问的最大流跑完以后的残量网络上建,而不是重建…… 我们令残量网络上原有的弧的费用全部为0(因为 ...
- 【树形贪心】【UVA1267】Network
重要意义:复习好久没写的邻接表了. Network, Seoul 2007, LA3902 Consider a tree network with n nodes where the interna ...
- 【OpenStack】network相关知识学习
network 类型 local:通信不跨主机,必须同一网段,主要做单机测试使用: flat:统计可以跨主机,但是需要在同一网段: 每个 flat network 都会独占一个物理网卡 计算节点上 b ...
- 【转】[Network] 计算机网络基础知识总结
阅读目录 1. 网络层次划分 2. OSI七层网络模型 3. IP地址 4. 子网掩码及网络划分 5. ARP/RARP协议 6. 路由选择协议 7. TCP/IP协议 8. UDP协议 9. DNS ...
- 【图论】Network of Schools
[POJ1236]Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18969 Acc ...
- 【leetcode】Network Delay Time
题目: There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edge ...
- BZOJ 1834 【ZJOI2010】 network 网络扩容
Description 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用.求: 1. 在不扩容的情况下,1到N的最大流: 2. 将1到N的最大流增加K所需的 ...
- 【BZOJ3732】 Network Kruskal+倍增lca
Description 给你N个点的无向图 (1 <= N <= 15,000),记为:1…N. 图中有M条边 (1 <= M <= 30,000) ,第j条边的长度为: d_ ...
随机推荐
- 第24章 SEH结构化异常处理_异常处理及软件异常
24.1 程序的结构 (1)try/except框架 __try{ //被保护的代码块 …… } __except(except fileter/*异常过滤程序*/){ //异常处理程序 } (2) ...
- 分布式环境下Unique ID生成方法
ID即标示符,在某个搜索域内能唯一标示其中某个对象.在关系型数据库中每个表都需要定义一个主键来唯一标示一条记录.为了方便一般都会使用一个auto_increment属性的整形数做为ID.因为数据库本身 ...
- MVC权限验证之ActionFilterAttribute
参考:http://www.cnblogs.com/waitingfor/archive/2011/12/27/2303784.html ActionFilterAttribute是Action过滤类 ...
- C# 杂项
1,函数访问等级必须高于参数等级,如函数等级是PUBLIC,则参数必须高于等于PUBLIC,若为INTERNAL 则不行.INTERNAL 低于PUBLIC, 用于同一个程序集内引用,PUBLIC则可 ...
- ThinkPHP 3.2.3 ----- 验证码
显示验证码 首先在Home/Controller下创建一个公共控制器PublicController 1 <?php 2 namespace Home\Controller; 3 4 use T ...
- Flash相关知识
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" wid ...
- C# 延迟处理类 Lazy
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lazy ...
- windows 7 安装 scrapy
基于64位 win7 系统 先到 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载四个 wheel 文件: 1. lxml-3.4.4-cp27-none-w ...
- Android调用基于.net的WebService
在实际开发项目中,有时候会为Android开发团队提供一些接口,一般是以asmx文件的方式来承载.而公布出去的数据一般上都是标准的json数据.但是在实际过程中,发现Android团队那边并不是通过将 ...
- python数字图像处理(4):图像数据类型及颜色空间转换
一.图像数据类型及转换 在skimage中,一张图片就是一个简单的numpy数组,数组的数据类型有很多种,相互之间也可以转换.这些数据类型及取值范围如下表所示: Data type Range uin ...