layout: post

title: 训练指南 UVALive - 5135 (双连通分量)

author: "luowentaoaa"

catalog: true

mathjax: true

tags:

- 双连通分量

- 图论

- 训练指南


Mining Your Own Business

UVALive - 5135

题意

在一张无向图中,将一些点涂上黑色,使得删掉图中任何一个点时,每个连通分量至少有一个黑点。问最少能涂几个黑点,并且在涂最少的情况下有几种方案。

显然,一定不能涂割点。对于每一个连通分量,如果有1个割点,则必须涂上分量内除割点之外的任意一个点,如果有多个(2个及以上)割点,则这个分量不需要涂色。如果整张图都没有割点,那么任选两个点涂色即可,之所以要涂两个,是要防止删掉的电恰是黑点的情况。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL; struct Edge{
int u,v;
};
///割顶 bccno 无意义
int pre[maxn],iscut[maxn],bccno[maxn],dfs_clock,bcc_cut;
vector<int>G[maxn],bcc[maxn];
stack<Edge>S;
int dfs(int u,int fa){
int lowu = pre[u] = ++dfs_clock;
int child = 0;
for(int i = 0; i < G[u].size(); i++){
int v =G[u][i];
Edge e = (Edge){u,v};
if(!pre[v]){ ///没有访问过
S.push(e);
child++;
int lowv = dfs(v, u);
lowu=min(lowu, lowv); ///用后代更新
if(lowv >= pre[u]){
iscut[u]=true;
bcc_cut++;bcc[bcc_cut].clear(); ///注意 bcc从1开始
for(;;){
Edge x=S.top();S.pop();
if(bccno[x.u] != bcc_cut){bcc[bcc_cut].push_back(x.u);bccno[x.u]=bcc_cut;}
if(bccno[x.v] != bcc_cut){bcc[bcc_cut].push_back(x.v);bccno[x.v]=bcc_cut;}
if(x.u==u&&x.v==v)break;
}
}
}
else if(pre[v] < pre[u] && v !=fa){
S.push(e);
lowu = min(lowu,pre[v]);
}
}
if(fa < 0 && child == 1) iscut[u] = 0;
return lowu;
}
void find_bcc(int n){
memset(pre, 0, sizeof(pre));
memset(iscut, 0, sizeof(iscut));
memset(bccno, 0, sizeof(bccno));
dfs_clock = bcc_cut = 0;
for(int i = 0; i < n;i++)
if(!pre[i])dfs(i,-1);
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,Case=1;
int mx;
while(cin>>n&&n){
for(int i=0;i<2*n;i++)G[i].clear();
mx=-inf;
for(int i=0;i<n;i++){
int u,v;
cin>>u>>v;mx=max(mx,max(u,v));
u--,v--;
G[u].push_back(v);
G[v].push_back(u);
}
find_bcc(mx);
ll ans1=0,ans2=1;
for(int i=1;i<=bcc_cut;i++){
int cut_cnt=0;
for(int j=0;j<bcc[i].size();j++)
if(iscut[bcc[i][j]])cut_cnt++;
if(cut_cnt==1){
ans1++;
ans2*=(ll)(bcc[i].size()-cut_cnt);
}
}
if(bcc_cut==1){
ans1=2;
ans2=ll(bcc[1].size()*(bcc[1].size()*1LL-1LL)/2LL);
}
cout<<"Case "<<Case++<<": "<<ans1<<" "<<ans2<<endl;
}
return 0;
}

训练指南 UVALive - 5135 (双连通分量)的更多相关文章

  1. 训练指南 UVALive - 3523 (双联通分量 + 二分图染色)

    layout: post title: 训练指南 UVALive - 3523 (双联通分量 + 二分图染色) author: "luowentaoaa" catalog: tru ...

  2. 训练指南 UVALive - 4287 (强连通分量+缩点)

    layout: post title: 训练指南 UVALive - 4287 (强连通分量+缩点) author: "luowentaoaa" catalog: true mat ...

  3. 训练指南 UVALive - 3126(DAG最小路径覆盖)

    layout: post title: 训练指南 UVALive - 3126(DAG最小路径覆盖) author: "luowentaoaa" catalog: true mat ...

  4. 训练指南 UVALive - 3415(最大点独立集)

    layout: post title: 训练指南 UVALive - 3415(最大点独立集) author: "luowentaoaa" catalog: true mathja ...

  5. 训练指南 UVALive - 3989(稳定婚姻问题)

    ayout: post title: 训练指南 UVALive - 3989(稳定婚姻问题) author: "luowentaoaa" catalog: true mathjax ...

  6. 训练指南 UVALive - 4043(二分图匹配 + KM算法)

    layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...

  7. 训练指南 UVALive - 5713(最小生成树 + 次小生成树)

    layout: post title: 训练指南 UVALive - 5713(最小生成树 + 次小生成树) author: "luowentaoaa" catalog: true ...

  8. 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树)

    layout: post title: 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树) author: "luowentaoaa" ca ...

  9. 训练指南 UVALive - 3713 (2-SAT)

    layout: post title: 训练指南 UVALive - 3713 (2-SAT) author: "luowentaoaa" catalog: true mathja ...

随机推荐

  1. 51nod 1831 小C的游戏(博弈论+打表)

    比较坑的题目. 题意就是:给出一堆石子,一次操作可以变成它的约数个,也可以拿只拿一个,不能变成一个,最后拿的人输. 经过打表发现 几乎所有质数都是先手必败的,几乎所有合数都是先手必胜的 只有几个例外, ...

  2. 工具——SVN常用命令

    SVN一般都是团队合作做一个项目所需用到的,为了是版本的统一 ;1. Check out——从服务器端取得代码    把服务器资料库里存放的某个项目代码取出来,放到本地主机中,这个动作叫做“check ...

  3. C语言的getopt

    By francis_hao    Jul 5,2017   getopt:分析命令行选项 概述 #include <unistd.h>int getopt(int argc, char ...

  4. git 的证书重新设置,以及如何让git 记住提交的用户名和密码

    1.git 的证书的重新设置的命令是: git config --system --unset credential.helper 2.保存git的用户名和密码注意这里是全局保存 git config ...

  5. bzoj 4624 农场种植 fft

    4624: 农场种植 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 48  Solved: 31[Submit][Status][Discuss] D ...

  6. css和javascript中图片路径的不同

    之前在写前端代码时,在图片路径的设置那里经常会遇到一个问题.比方说,我 (1)在根目录下面新建了个"images"文夹,里面放了张图片top.gif (2)在根目录下另外新建了两个 ...

  7. oracle 包和包实现

    包: create or replace package sp_pexam_clear as --定义结构体 /*type re_stu is record( rname student.name%t ...

  8. 转:Spring AOP 注解方式实现的一些“坑”

    使用过Spring AOP的注解方式实现,也入过不少坑,现在做一下记录,希望有同样需求的朋友可以少走弯路 使用之前还是先过一下官方文档吧,至少可以少走弯路,不用担心英文读不懂,其实只看代码例子就能理解 ...

  9. python并发进程

    1 引言 2 创建进程 2.1 通过定义函数的方式创建进程 2.2 通过定义类的方式创建进程 3 Process中常用属性和方法 3.1 守护进程:daemon 3.2 进程终结于存活检查:termi ...

  10. bzoj3790 manacher算法+贪心

    紧跟jk大佬的步伐 这道题哇 因为机器一能生成回文串 所以我们只要用manacher跑一遍求出q[i]这样就把问题转化成了类似线段覆盖的题目 贪心就好了 至于,BIT优化dp我不会所以直接贪心了 注意 ...