求出 bcc 后再……根据大白书上的思路即可。

  然后我用的是自定义的 stack 类模板:

 #include<cstdio>
#include<cstring>
#include<vector>
//#include<stack>
#include<stdexcept>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = ; template <typename T, size_t SIZE = N>
class stack {
T *val;
size_t tot;
size_t limit;
public:
stack(size_t limit = SIZE): limit(limit) {
val = (T*)malloc(sizeof(T) * limit);
tot = ;
}
stack(const stack<T> &s2): limit(s2.limit), tot(s2.tot) {
val = (T*)malloc(sizeof(T) * limit);
for(size_t i = ; i < tot; ++i)
val[i] = s2.val[i];
}
stack& operator = (const stack<T> &s2) {
tot = s2.tot;
limit = s2.limit;
T *temp = (T*)malloc(sizeof(T) * s2.limit);
for(size_t i = ; i < s2.tot; ++i)
temp[i] = s2.val[i];
free(val);
this->val = temp;
}
void push(const T &x) {
if(tot == limit) {
stack<T> temp(*this);
free(val);
val = (T*)malloc(sizeof(T) * (limit <<= ));
for(size_t i = ; i < temp.tot; ++i)
val[i] = temp.val[i];
}
val[tot++] = x;
}
void pop() {
if(tot == ) throw out_of_range("Stack less flow at Stack<T>::pop()");
--tot;
}
T top() const {
if(tot == ) throw out_of_range("Stack less flow at Stack<T>::top()");
return val[tot - ];
}
size_t size() const { return tot; }
bool empty() const { return tot == ; }
void clear() { tot = ; }
~stack() { free(val); }
}; struct Edge {
int u,v;
Edge(int u, int v): u(u), v(v) {}
}; vector<int> g[N], bcc[N];
int pre[N], iscut[N], bccno[N], dfs_clock, bcc_cnt;
stack<Edge, N> s; int dfs(int u, int fa) {
int lowu = pre[u] = ++dfs_clock;
int child = ;
for(int i = ; 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] = ;
++bcc_cnt;
bcc[bcc_cnt].clear();
while() {
Edge x = s.top(); s.pop();
if(bccno[x.u] != bcc_cnt) {
bccno[x.u] = bcc_cnt;
bcc[bcc_cnt].push_back(x.u);
}
if(bccno[x.v] != bcc_cnt) {
bccno[x.v] = bcc_cnt;
bcc[bcc_cnt].push_back(x.v);
}
if(x.u == u && x.v == v) break;
}
}
}
else if(pre[v] < pre[u] && v != fa) {
lowu = min(lowu, pre[v]);
s.push(e);
}
}
if(fa < && child == ) iscut[u] = ;
return lowu;
} void find_bcc(int n) {
memset(pre, , sizeof pre);
memset(iscut, , sizeof iscut);
memset(bccno, , sizeof bccno);
dfs_clock = bcc_cnt = ;
for(int i = ; i < n; ++i)
if(!pre[i]) dfs(i, -);
} int main() {
int n,x,y,Case = , maxn = ;
while(~scanf("%d",&n),n) {
for(int i = ; i <= maxn; ++i)
g[i].clear();
maxn = ;
for(int i = ; i < n; ++i) {
scanf("%d %d",&x,&y);
maxn = max(maxn, x);
maxn = max(maxn, y);
g[x].push_back(y);
g[y].push_back(x);
}
find_bcc(maxn + );
LL ans1 = , ans2 = ;
for(int i = ; i <= bcc_cnt; ++i) {
int cut = ;
for(int j = ; j < bcc[i].size(); ++j)
if(iscut[bcc[i][j]]) ++cut;
if(cut == ) {
++ans1;
ans2 *= bcc[i].size() - cut;
}
}
if(bcc_cnt == ) {
ans1 = ;
ans2 = (LL)bcc[].size() * (bcc[].size() - ) / ;
}
printf("Case %d: %lld %lld\n",++Case, ans1, ans2);
}
return ;
}

LA 5135 Mining Your Own Business的更多相关文章

  1. UVALive - 5135 - Mining Your Own Business(双连通分量+思维)

    Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...

  2. 【LA】5135 Mining Your Own Business

    [算法]点双连通分量 [题解]详见<算法竞赛入门竞赛入门经典训练指南>P318-319 细节在代码中用important标注. #include<cstdio> #includ ...

  3. UVALive - 5135 Mining Your Own Business

    刘汝佳白书上面的一道题目:题意是给定一个联通分量,求出割顶以及双连通分量的个数,并且要求出安放安全井的种类数,也就是每个双连通分量中结点数(除开 割顶)个数相乘,对于有2个及以上割顶的双连通分量可以不 ...

  4. UVALive 5135 Mining Your Own Business 双连通分量 2011final

    题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太平井逃脱, ...

  5. UVALive 5135 Mining Your Own Business 双连通分量

    据说这是一道Word Final的题,Orz... 原题链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...

  6. HDU3844 Mining Your Own Business

    HDU3844 Mining Your Own Business 问题描述John Digger是一个大型illudium phosdex矿的所有者.该矿山由一系列隧道组成,这些隧道在各个大型交叉口相 ...

  7. 「题解报告」SP16185 Mining your own business

    题解 SP16185 Mining your own business 原题传送门 题意 给你一个无向图,求至少安装多少个太平井,才能使不管那个点封闭,其他点都可以与有太平井的点联通. 题解 其他题解 ...

  8. Mining Your Own Business UVALive - 5135(点双联通分量)

    these days I‘m tired!,but very happy... #include<cstdio> #include<cstring> #include<s ...

  9. UVA5135 Mining Your Own Business ( 无向图双连通分量)

    题目链接 题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太 ...

随机推荐

  1. python 拷贝文件夹下所有的文件到指定文件夹(不包括目录)

    1.随便简单些写了一下.直接粘结代码,只是简单的实现一下,还很多需要完善和扩展的地方,比如忽略掉后缀文件,删除文件 如果排除的某些的话可以用: sourceF.find('.后缀')>0 2.注 ...

  2. SlickGrid example 2: 按想要的风格展示列

    先上效果图. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// ...

  3. 跨站点脚本编制实例(AppScan扫描结果)

    最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中有很多是关于跨站点脚本编制问题的.下面就把这块东西分享出来. 原创文章,转载请注明 ------------------ ...

  4. ROADS

    ROADS Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11977 Accepted: 4429 Description N ...

  5. mongoDB Replica集群配置(1主+1从+1仲裁)

    1.mongoDB节点介绍 主节点(Primary) 在复制集中,主节点是唯一能够接收写请求的节点.MongoDB在主节点进行写操作,并将这些操作记录到主节点的oplog中.而从节点将会从oplog复 ...

  6. gulp 建立一个简单的自动化

    前端项目需要的功能: 1.图片(压缩图片支持jpg.png.gif) 2.样式 (支持sass 同时支持合并.压缩.重命名) 3.javascript (检查.合并.压缩.重命名) 4.html (压 ...

  7. 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) I

    链接:http://codeforces.com/gym/101116 题意:选六个数,必须出现次数最多,且数字最小,如果出现7优先加入7 解法:排序,出现7优先加入7,最后再将6个数排序 #incl ...

  8. 基于kickstart定制自动化安装的linux镜像系统

    使用软件和平台 1.基于平台:                  Vmware workstation 8.0 2.基于系统镜像:               rhel-server-5.8-i386 ...

  9. 改变了一下blog的主题,很开心

    调整了一下博客的样式,之前一直想改变下,一直不会这次终于摸索出来一点,不过是最简单的,就是在管理里面的设置,可以定制css代码,修改修改,页面就跟着你的想法走了,有时间好好修改下,暂时这个样子,简单大 ...

  10. C#实现ActiveX控件开发与部署

    现在,我们手里已经有了这个控件包:QRCode.cab,下面我们编写一个测试的网页 <html> <head> <title>无标题页</title> ...