首先,如果图本来就是一个点双联通的(即不存在割点),那么从这个图中选出任意两个点就OK了。

如果这个图存在割点,那么我们把割点拿掉后图就会变得支离破碎了。对于那种只和一个割点相连的块,这个块中至少要选一个点出来建逃生通道,而且可以任意选择,而对于那种和多个割点相连的块则没必要选点出来建逃生通道。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAXN 100010
#define MAXM 100010
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long LL;
int dfn[MAXN], low[MAXN], h[MAXN], ind;
bool vis[MAXN];
int N, M, first[MAXN], e, next[MAXM], v[MAXM], col[MAXN];
struct Edge
{
int x, y;
}edge[MAXM];
void dfs(int u, int p, int o)
{
dfn[u] = low[u] = ++ ind;
int cnt = ;
for(int i = first[u]; i != -; i = next[i])
{
if(v[i] == p) continue;
if(!dfn[v[i]])
{
++ cnt;
dfs(v[i], u, o);
low[u] = std::min(low[u], low[v[i]]);
if(u == o && cnt > ) h[u] = ;
else if(u != o && low[v[i]] >= dfn[u]) h[u] = ;
}
else low[u] = std::min(low[u], dfn[v[i]]);
}
}
void tarjan()
{
for(int i = ; i <= N; i ++)
low[i] = dfn[i] = h[i] = ;
ind = ;
dfs(i, -, i);
}
void add(int x, int y)
{
v[e] = y;
next[e] = first[x], first[x] = e ++;
}
void input()
{
N = ;
for(int i = ; i < M; i ++)
{
scanf("%d%d", &edge[i].x, &edge[i].y);
N = std::max(edge[i].x, N);
N = std::max(edge[i].y, N);
}
memset(first, -, sizeof(first[]) * (N + )), e = ;
for(int i = ; i < M; i ++)
add(edge[i].x, edge[i].y), add(edge[i].y, edge[i].x);
}
void find(int x, int c, int &pn, int &cn)
{
vis[x] = true, ++ pn;
for(int i = first[x]; i != -; i = next[i])
{
int y = v[i];
if(vis[y]) continue;
if(h[y])
{
if(col[y] != c) col[y] = c, ++ cn;
continue;
}
find(y, c, pn, cn);
}
}
void process()
{
tarjan();
memset(vis, , sizeof(vis[]) * (N + ));
memset(col, , sizeof(col[]) * (N + ));
LL ans = ;
int cnt = ;
for(int i = ; i <= N; i ++)
if(!h[i] && !vis[i])
{
int pn = , cn = ;
find(i, i, pn, cn);
if(cn == ) ans *= (LL)pn * (pn - ) / , cnt += ;
else if(cn == ) ans *= pn, ++ cnt;
}
printf("%d %I64d\n", cnt, ans);
}
int main()
{
int t = ;
while(scanf("%d", &M), M > )
{
input();
printf("Case %d: ", ++ t);
process();
}
return ;
}

最新文章

  1. @Html.Partial和@Html.Action区别
  2. led灯的翻转函数
  3. (旧)子数涵数&#183;DW——网页制作的流程
  4. Opencv不用每次创建项目配置vs2010 vc++目录 库目录等项
  5. 在linux(CentOS-6.7_x86_64)上安装mysql成功记录
  6. apache2反向代理node.js应用
  7. hive 安装教程
  8. Cannot retrieve metalink for repository: epel. Please verify its path and try again
  9. Machine Learning - XI. Machine Learning System Design机器学习系统的设计(Week 6)
  10. hdu4185二分图匹配
  11. C-图文上边对齐
  12. IDEA热部署(一)---解析关键配置。
  13. Retinex图像增强算法代码
  14. OpenOCD的概念,安装和使用
  15. C++ MFC------ 快捷键
  16. python--爬取豆瓣热门国产电视剧保存为文件
  17. CSS3-flex弹性布局之flex属性
  18. 凭什么相信你,我的CNN模型
  19. Qt之创建并使用静态链接库
  20. c#通用配置文件读写类与格式转换(xml,ini,json)

热门文章

  1. STL之map应用 +hash表(51nod 1095)
  2. [转]node.js学习笔记(二)
  3. Dynamic CRM 2013学习笔记(四十一)流程4 - 异步工作流(Workflow)用法图解
  4. Bad version number in .class file
  5. 写给自己看的Linux运维基础(四) - python环境
  6. Spring-Context之二:使用Spring提供的测试框架进行测试
  7. 使用media Queries实现一个响应式的菜单
  8. [BTS] BizTalk With EF
  9. 工作圈redis 使用
  10. 通过Greasemonkey实现网页图片自动点击