UVALive 5135 Mining Your Own Bussiness【tarjan点双】
题目大意
给你一个无向连通图,让你给一些点染上黑色,需要满足染色之后,断开任意一个节点,要满足任意一个联通块中剩下的节点中至少有一个黑点
思路
一开始想的是把每一个点双联通分量都把除了割点的size乘上
然后发现随手卡掉
然后发现一下性质
首先所有相邻点双联通分量一定有公共的割点
如果一个双联通分量里面只包含了一个割点,那么如果断掉这个割点那么这个双联通分量就被孤立了
所以这样的双联通分量至少选择一个点
然后如果一个双联通分量有大于等于两个割点,就算一个被割掉了另外一边至少连接着1个只有一个割点的点双联通分量
那么就很容易做了
特判一下如果整张图都是一个双联通分量那么就是任意选两个点就可以了
//Author: dream_maker
#include<bits/stdc++.h>
using namespace std;
//----------------------------------------------
//typename
typedef long long ll;
//convenient for
#define fu(a, b, c) for (int a = b; a <= c; ++a)
#define fd(a, b, c) for (int a = b; a >= c; --a)
#define fv(a, b) for (int a = 0; a < (signed)b.size(); ++a)
//inf of different typename
const int INF_of_int = 1e9;
const ll INF_of_ll = 1e18;
//fast read and write
template <typename T>
void Read(T &x) {
bool w = 1;x = 0;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') w = 0, c = getchar();
while (isdigit(c)) {
x = (x<<1) + (x<<3) + c -'0';
c = getchar();
}
if (!w) x = -x;
}
template <typename T>
void Write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) Write(x / 10);
putchar(x % 10 + '0');
}
//----------------------------------------------
typedef pair<int, int> pi;
#define fi first
#define se second
const int N = 5e4 + 10;
struct Edge {
int v, nxt;
} E[N << 1];
stack<pi > st;
int head[N], tot = 0, ind = 0, cnt_bcc = 0;
int n, m, dfn[N], low[N], siz[N], bel[N];
bool iscut[N];
vector<int> g[N];
void init() {
fu(i, 1, N - 1) dfn[i] = low[i] = bel[i] = head[i] = siz[i] = 0, iscut[i] = 0;
tot = ind = cnt_bcc = 0;
}
void add(int u, int v) {
E[++tot] = (Edge) {v, head[u]};
head[u] = tot;
}
void tarjan(int u, int fa) {
dfn[u] = low[u] = ++ind;
int num = 0;
for (int i = head[u]; i; i = E[i].nxt) {
int v = E[i].v;
if (v == fa) continue;
if (!dfn[v]) {
st.push(pi(u, v));
++num;
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= dfn[u]) {
iscut[u] = 1;
g[++cnt_bcc].clear();
pi now;
do {
now = st.top(); st.pop();
if (bel[now.fi] != cnt_bcc) {
g[cnt_bcc].push_back(now.fi);
bel[now.fi] = cnt_bcc;
}
if (bel[now.se] != cnt_bcc) {
g[cnt_bcc].push_back(now.se);
bel[now.se] = cnt_bcc;
}
} while (now.fi != u || now.se != v);
}
} else low[u] = min(low[u], dfn[v]);
}
if (num < 2 && !fa) iscut[u] = 0;
}
void solve() {
n = 0;
init();
fu(i, 1, m) {
int u, v;
Read(u), Read(v);
add(u, v);
add(v, u);
n = max(n, max(u, v));
}
tarjan(1, 0);
if (cnt_bcc == 1) {
Write(2), putchar(' ');
Write(ll(n) * ll(n - 1) / 2), putchar('\n');
} else {
ll ans1 = 0, ans2 = 1;
fu(i, 1, cnt_bcc) {
int cntnow = 0;
fv(j, g[i])
if (iscut[g[i][j]]) ++cntnow;
if (cntnow == 1)
++ans1, ans2 *= (ll) g[i].size() - 1;
}
Write(ans1), putchar(' ');
Write(ans2), putchar('\n');
}
}
int main() {
#ifdef dream_maker
freopen("input.txt", "r", stdin);
#endif
int id = 0;
while (1) {
Read(m);
if (!m) return 0;
printf("Case %d: ", ++id);
solve();
}
return 0;
}
UVALive 5135 Mining Your Own Bussiness【tarjan点双】的更多相关文章
- UVALive - 5135 - Mining Your Own Business(双连通分量+思维)
Problem UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...
- UVALive 5135 Mining Your Own Business 双连通分量
据说这是一道Word Final的题,Orz... 原题链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...
- UVALive - 5135 Mining Your Own Business
刘汝佳白书上面的一道题目:题意是给定一个联通分量,求出割顶以及双连通分量的个数,并且要求出安放安全井的种类数,也就是每个双连通分量中结点数(除开 割顶)个数相乘,对于有2个及以上割顶的双连通分量可以不 ...
- UVALive 5135 Mining Your Own Business 双连通分量 2011final
题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太平井逃脱, ...
- 训练指南 UVALive - 5135 (双连通分量)
layout: post title: 训练指南 UVALive - 5135 (双连通分量) author: "luowentaoaa" catalog: true mathja ...
- 【Codefoces487E/UOJ#30】Tourists Tarjan 点双连通分量 + 树链剖分
E. Tourists time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard inpu ...
- Mining Your Own Business UVALive - 5135(点双联通分量)
these days I‘m tired!,but very happy... #include<cstdio> #include<cstring> #include<s ...
- 【LA】5135 Mining Your Own Business
[算法]点双连通分量 [题解]详见<算法竞赛入门竞赛入门经典训练指南>P318-319 细节在代码中用important标注. #include<cstdio> #includ ...
- LA 5135 Mining Your Own Business
求出 bcc 后再……根据大白书上的思路即可. 然后我用的是自定义的 stack 类模板: #include<cstdio> #include<cstring> #includ ...
随机推荐
- 4.1 Routing -- Introduction
一.Routing 1. 当用户与应用程序交互时,它会经过很多状态.Ember.js为你提供了有用的工具去管理它的状态和扩展你的app. 2. 要理解为什么这是重要的,假设我们正在编写一个Web应用程 ...
- F题:等差区间(RMQ||线段树)
原题大意:原题链接 题解链接 给定一个长为n的数组元素和q次区间[l,r]询问,判断区间[l,r]内元素排序后能否构成等差数列 #include<cmath> #include<c ...
- 在Qt中如何编写插件,加载插件和卸载插件(转)
Qt提供了一个类QPluginLoader来加载静态库和动态库,在Qt中,Qt把动态库和静态库都看成是一个插件,使用QPluginLoader来加载和卸载这些库.由于在开发项目的过程中,要开发一套插件 ...
- # 20145122 《Java程序设计》第3周学习总结
教材学习内容总结 1一类一文件. 2一个原始码中只能有一个公开类,一个类定义产生一个.class文档. 3如果参考名称与数据成员同名时,将参数的值指定给对象的数据成员时要在数据成员前加this. 4当 ...
- 20159212杨翔实验一(熟悉Java开发环境)实验报告
实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验步骤与体会 一.命令行下Java程序开发 1.操作过程 在虚拟环境中 ...
- InstallShield 2015 Premier的Basic MSI Project如何在卸载时删除残留的文件 (转)
转载:http://blog.csdn.net/zztoll/article/details/54018615#comments 先说下缘由,我在用InstallShield 2015 Premier ...
- Migrating from Spring 3 to Spring 4 - org.springframework.scheduling.quartz.CronTriggerBean
I'm trying to migrate from spring 3.0.5 to spring 4.1.X . Spring 3 has Class named as "org.spri ...
- hdu 1004 Let the Balloon Rise strcmp、map、trie树
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- python学习笔记(HTMLTestRunner在Py3的兼容)
博主最近开始重构自动化框架并且向Py3上兼容 第一个问题就是生成测试报告的HTMLTestRunner,由于此模块是基于Py2开发的,这里需要修改源码 # 94行 # import StringIO ...
- vSphere Client的拷贝 粘帖 功能
Windows Client OS的情况下, Remote Desktop 自带拷贝/粘帖 功能, 所以一直没在意. 这回用CentOS, 比起vnc viewer , 感觉还是自带的 vSphere ...