LINK1

LINK2


题目大意

给你一个无向连通图,让你给一些点染上黑色,需要满足染色之后,断开任意一个节点,要满足任意一个联通块中剩下的节点中至少有一个黑点

思路

一开始想的是把每一个点双联通分量都把除了割点的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点双】的更多相关文章

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

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

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

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

  3. UVALive - 5135 Mining Your Own Business

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

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

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

  5. 训练指南 UVALive - 5135 (双连通分量)

    layout: post title: 训练指南 UVALive - 5135 (双连通分量) author: "luowentaoaa" catalog: true mathja ...

  6. 【Codefoces487E/UOJ#30】Tourists Tarjan 点双连通分量 + 树链剖分

    E. Tourists time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard inpu ...

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

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

  8. 【LA】5135 Mining Your Own Business

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

  9. LA 5135 Mining Your Own Business

    求出 bcc 后再……根据大白书上的思路即可. 然后我用的是自定义的 stack 类模板: #include<cstdio> #include<cstring> #includ ...

随机推荐

  1. 3.10 Templates -- Development Helpers

    一.Development Helpers Handlebar和Ember有好多个辅助器可以使模板开发更容易. 这些辅助器输出变量到浏览器的控制台,或者从模板中激活debugger. 二.Loggin ...

  2. 禁止或强制使用堆分配---《C++必知必会》 条款34

    有时候,指明一些特定类的对象不应该被分配到堆(heap)上是个好主意.通常这是为了确保该对象的析构函数一定会得到调用.维护对象本身(body object)的引用计数的句柄对象(handle obje ...

  3. 画柱状图Java

    样例输入:THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.THIS IS AN EXAMPLE TO TEST FOR YOURHISTOGRAM PROGR ...

  4. Bootstrap fileinput v3.0(ssm版)

    说明在上一个版本即Bootstrap fileinput v2.0(ssm版)的基础上,增加了多处都需要上传的需求 核心代码ArticleController.java package com.isd ...

  5. 2018-2019 ACM-ICPC, Asia East Continent Finals Solution

    D. Deja vu of … Go Players 签. #include <bits/stdc++.h> using namespace std; int t, n, m; int m ...

  6. centos6.5搭建svn

    检查已经安装版本  rpm -qa subversion如果存在旧版本,卸载yum remove subversion 安装svn yum install subversion 验证是否安装成功 sv ...

  7. mssql查询所有上下级

    if exists (select * from sys.all_objects where name='GetOrgTreeByID') begin drop proc GetOrgTreeByID ...

  8. 20145335郝昊《网络攻防》Bof逆向基础——ShellCode注入与执行

    20145335郝昊<网络攻防>Bof逆向基础--ShellCode注入与执行 实验原理 关于ShellCode:ShellCode是一段代码,作为数据发送给受攻击服务器,是溢出程序和蠕虫 ...

  9. POJ 2762 Going from u to v or from v to u? (判断单连通)

    http://poj.org/problem?id=2762 题意:给出有向图,判断任意两个点u和v,是否可以从u到v或者从v到u. 思路: 判断图是否是单连通的. 首先来一遍强连通缩点,重新建立新图 ...

  10. markdown哈哈

    function box(){ 世界你好 }