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. mysql主从复制,及扩展

    一.MySQL简单复制相关概念: 1. mysql复制的意义:Mysql复制是使得mysql完成高性能应用的前提 2. mysql复制的机制: SLAVE端线程: IO thread: 向主服务请求二 ...

  2. VC中加载LIB库文件的三种方法

    VC中加载LIB库文件的三种方法 在VC中加载LIB文件的三种方法如下: 方法1:LIB文件直接加入到工程文件列表中   在VC中打开File View一页,选中工程名,单击鼠标右键,然后选中&quo ...

  3. 手把手教你学node.js 之使用 eventproxy 控制并发

    使用 eventproxy 控制并发 目标 建立一个 lesson4 项目,在其中编写代码. 代码的入口是 app.js,当调用 node app.js 时,它会输出 CNode(https://cn ...

  4. Python numpy有什么用?

    NumPy is the fundamental package for scientific computing with Python.就是科学计算包. a powerful N-dimensio ...

  5. 【分页问题】elasticsearch 深分页问题以及解决方法

    本文主要参考: 1.https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html ...

  6. Gym 101246G Revolutionary Roads

    http://codeforces.com/gym/101246/problem/G 题意: 给出一个有向图,现在可以把图中的任意一条边改为无向边,问强连通分量最多可以有多少个点,在此情况下输出所有能 ...

  7. UVa 12034 比赛名次(递推)

    https://vjudge.net/problem/UVA-12034 题意: A.B两人赛马,最终名次有3种可能:并列第一:A第一B第二:B第一A第二.输入n,求n人赛马时最终名次的可能性的个数除 ...

  8. Question: Should I use reads with good quality but failed-vendor flag?--biostart for vendor quality

    https://www.biostars.org/p/198405/ Quick question is: I have some mapped reads in bam file which hav ...

  9. Win7SDK

    1.ISO下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=8442 2.可供下载的 版本有3个,网上搜到的解释: GRMSD ...

  10. rxjava rxandroid使用遇到的坑

    今天在解决一个界面加载本地数据库数据的时候,使用rxjava在指定io线程操作是遇到一个问题,即使指定了在io线程操作,可是界面还是卡顿,最后通过打印线程Thread.currentThread(). ...