【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_ ...
随机推荐
- 三维世界的Gizmos
Unity和Maya 今天在美术同事那儿了解些Maya常识,加上自己在Unity3D中的一点儿小操作,记录一下Gizmos 之前就知道Maya和Unity3D的轴向是一致的,在同事那儿看他操作Maya ...
- Cobbler自动化批量安装linux服务器的操作记录
Cobbler为何物?Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows.该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命 ...
- Android中Intent传值与Bundle传值的区别详解
Android中Intent传值与Bundle传值的区别详解 举个例子我现在要从A界面跳转到B界面或者C界面 这样的话 我就需要写2个Intent如果你还要涉及的传值的话 你的Intent就要写两 ...
- no.5.print sum
#-*-coding=utf-8-*- for a in range(1,50,1): for b in range(1,50,1): for c in range(1,50,1): if a+b+c ...
- Android EventBus源码解析 带你深入理解EventBus
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/40920453,本文出自:[张鸿洋的博客] 上一篇带大家初步了解了EventBus ...
- Android RotateAnimation详解
RotateAnimation旋转坐标系为以旋转点为坐标系(0,0)点.x轴为0度,顺时针方向旋转一定的角度.1.RotateAnimation(fromDegrees, toDegrees) [默认 ...
- 足球运动训练心得及经验分析-c语言学习调查
在准备预备作业02之前,我参考娄老师的提示,阅读了<[做中学(Learning By Doing)]之乒乓球刻意训练一年总结>一文. 在文章描述的字里行间,给予我的印象是系统.负责,娄老师 ...
- (转)Python实例手册
原文地址:http://hi.baidu.com/quanzhou722/item/cf4471f8e23d3149932af2a7 实在是太好的资料了,不得不转 python实例手册 #encodi ...
- Scrum敏捷精要
本文抽取Scrum中的一些重要思想和概念,对Scrum敏捷执行的主题流程进行精要的介绍. 一.基本思想 个体和互动 高于 流程和工具 工作的软件 高于 详尽的文档 客户合作 ...
- WP8.1&Win10开发:TextBox获取和失去焦点小技巧
获取焦点:用Focus方法让Textbox获取焦点.代码示例:textbox.Focus(FocusState.Pointer); 失去焦点:让其他控件获取焦点,如Textblock控件(注意要将Te ...