bzoj 2730: [HNOI2012]矿场搭建——tarjan求点双
Description
Input
输入文件有若干组数据,每组数据的第一行是一个正整数 N(N≤500),表示工地的隧道数,接下来的 N 行每行是用空格隔开的两个整数 S 和 T,表示挖 S 与挖煤点 T 由隧道直接连接。输入数据以 0 结尾。
Output
输入文件中有多少组数据,输出文件 output.txt 中就有多少行。每行对应一组输入数据的 结果。其中第 i 行以 Case i: 开始(注意大小写,Case 与 i 之间有空格,i 与:之间无空格,: 之后有空格),其后是用空格隔开的两个正整数,第一个正整数表示对于第 i 组输入数据至少需 要设置几个救援出口,第二个正整数表示对于第 i 组输入数据不同最少救援出口的设置方案总 数。输入数据保证答案小于 2^64。输出格式参照以下输入输出样例。
Sample Input
1 3
4 1
3 5
1 2
2 6
1 5
6 3
1 6
3 2
6
1 2
1 3
2 4
2 5
3 6
3 7
0
Sample Output
Case 2: 4 1
HINT
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using std::max;
using std::min;
const int M=1e3+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,m;
int first[M],cnt,buck[M];
struct node{int from,to,next;}e[*M];
void ins(int a,int b){e[++cnt]=(node){a,b,first[a]}; first[a]=cnt;}
void insert(int a,int b){ins(a,b); ins(b,a);}
int dfn[M],low[M],T,iscut[M];
int hc,sz[M],color[M],stk[M],top;
void clear(){
n=; cnt=; T=; hc=; top=;
memset(iscut,,sizeof(iscut));
memset(first,,sizeof(first));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(sz,,sizeof(sz));
memset(color,,sizeof(color));
memset(buck,,sizeof(buck));
}
void tarjan(int x,int fa){
low[x]=dfn[x]=++T;
int child=;
for(int i=first[x];i;i=e[i].next){
int now=e[i].to;
if(!dfn[now]){
stk[++top]=i;
child++;
tarjan(now,x);
low[x]=min(low[x],low[now]);
if(low[now]>=dfn[x]){
iscut[x]=;
hc++;
while(){
int k=stk[top--];
if(color[e[k].from]!=hc){
if(color[e[k].from]) buck[color[e[k].from]]++;
sz[hc]++; color[e[k].from]=hc;
}
if(color[e[k].to]!=hc){
if(color[e[k].to]) buck[color[e[k].to]]++;
sz[hc]++; color[e[k].to]=hc;
}
if(e[k].from==x&&e[k].to==now) break;
}
}
}
else if(dfn[now]<dfn[x]&&now!=fa) stk[++top]=i,low[x]=min(low[x],dfn[now]);
}
if(fa==-&&child==) iscut[x]=;
}
int main(){
int x,y,h=;
while(scanf("%d",&m)==&&m){
++h; clear();
for(int i=;i<=m;i++){
x=read(); y=read();
insert(x,y); n=max(n,max(x,y));
}
for(int i=;i<=n;i++)if(!dfn[i]) tarjan(i,-);
for(int i=;i<=n;i++)if(iscut[i]) buck[color[i]]++;
LL ans=;
int tot=;
for(int i=;i<=hc;i++){
if(buck[i]==) ans*=max(sz[i]-,),tot++;
if(!buck[i]) ans*=sz[i]*(sz[i]-)/,tot+=;
}
printf("Case %d: %d %lld\n",h,tot,ans);
}
return ;
}
bzoj 2730: [HNOI2012]矿场搭建——tarjan求点双的更多相关文章
- BZOJ 2730: [HNOI2012]矿场搭建( tarjan )
先tarjan求出割点.. 割点把图分成了几个双连通分量..只需dfs找出即可. 然后一个bcc有>2个割点, 那么这个bcc就不用建了, 因为一定可以走到其他救援出口. 只有一个割点的bcc就 ...
- 【刷题】BZOJ 2730 [HNOI2012]矿场搭建
Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一 ...
- bzoj 2730: [HNOI2012]矿场搭建【tarjan】
先tarjan找割点和点双连通分量,然后对一个点双,如果没有割点,那么需要建立两个出口(割掉一个另一个备用):如果只有一个割点,出口可以设立在任意一个非割点的地方:如果有两个及以上个割点,就不用建出口 ...
- bzoj 2730: [HNOI2012]矿场搭建
#include<cstdio> #include<cstring> #include<iostream> #define M 508 using namespac ...
- 【BZOJ】2730: [HNOI2012]矿场搭建【Tarjan找割点】【分联通块割点个数】
2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3230 Solved: 1540[Submit][Stat ...
- 【BZOJ2730】[HNOI2012]矿场搭建 Tarjan
[BZOJ2730][HNOI2012]矿场搭建 Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处. ...
- BZOJ 2730 矿场搭建 Tarjan求割点
思路: Tarjan求出来点双&割点 判一判就行了 //By SiriusRen #include <stack> #include <cstdio> #include ...
- BZOJ2730 [HNOI2012]矿场搭建 - Tarjan割点
Solution 输入中没有出现过的矿场点是不用考虑的, 所以不用考虑只有 一个点 的点双联通分量. 要使某个挖矿点倒塌, 相当于割去这个点, 所以我们求一遍割点和点双联通分量. 之后的点双联通分量构 ...
- [BZOJ2730][HNOI2012]矿场搭建(求割点)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2730 分析: 如果坍塌的点不是割点,那没什么影响,主要考虑坍塌的点是割点的情况. 显然 ...
随机推荐
- iOS-创建UIScrollerView(封装UIScrollerView)
创建继承于UIView的类WJImageScrollView,代码实现如下: WJImageScrollView.h #import <UIKit/UIKit.h> /**点击图片bloc ...
- ZOJ 1666 G-Square Coins
https://vjudge.net/contest/67836#problem/G People in Silverland use square coins. Not only they have ...
- yum 安装 redis php-redis
yum 安装 redis php-redis redis和php-redis在官方源上是没有的,需要安装其他的源,其他源的地址为 http://mirrors.ustc.edu.cn/fedora ...
- bsxfun函数
函数功能:两个数组间元素逐个计算的二值操作 使用方法:C=bsxfun(fun,A,B) 两个数组A合B间元素逐个计算的二值操作,fun是函数句柄或者m文件,也可以为如下内置函数: @plus 加@m ...
- Elasticsearch cat Apis
1._cat列入所有有效命令 GET /_cat 返回:有个猫...所以不难想象为啥是cat api =^.^= /_cat/allocation /_cat/shards /_cat/shards/ ...
- POJ3666:Making the Grade——题解
http://poj.org/problem?id=3666 题目大意:给n个数,每次操作可使一个数+1或-1,求最小操作数使得序列不下降或不上升. —————————————————————— 思路 ...
- PE格式示意图
- some of the properties associated with the solution could not be read解决方法
基于TFS管理的解决方案打开时提示:“some of the properties associated with the solution could not be read”,并不影响项目加载,O ...
- [CodeVs1227]方格取数2(最大费用最大流)
网络流24题的坑还没填完,真的要TJ? 题目大意:一个n*n的矩阵,每格有点权,从(1,1)出发,可以往右或者往下走,最后到达(n,n),每达到一格,把该格子的数取出来,该格子的数就变成0,这样一共走 ...
- 探索CAS无锁技术
前言:关于同步,很多人都知道synchronized,Reentrantlock等加锁技术,这种方式也很好理解,是在线程访问的临界区资源上建立一个阻塞机制,需要线程等待 其它线程释放了锁,它才能运行. ...