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 ...
随机推荐
- 关于c语言struct和typedef
C++中使用: struct test{ int x, y;};就可以定义一个名为 test的结构体,但C中很可能编译通不过.C语言并不支持在struct后使用标示符定义结构体的名字,test将 ...
- activiti 数据表设计
activiti数据表分为5个部分: 通用数据表.流程存储表.身份数据表.运行时数据表.历史数据表 1.通用(general)数据表 以ACT_GE开头 资源表-act_ge_btyearray: 用 ...
- 无界面Ubuntu服务器搭建selenium+chromedriver+VNC运行环境
搭建背景 有时候我们需要把基于selenium的爬虫放到服务器上跑的时候,就需要这样一套运行环境,其中VNC是虚拟的显示模式,用于排查定位线上问题以及实时运行情况. 搭建流程 安装虚拟输出设备:sud ...
- 使用NodeJS将文件或图像上传到服务器
原文链接:http://www.codeceo.com/article/nodejs-upload-file-to-server.html
- ubuntu 16.04下更换源和pip源【转】
本文转载自:https://blog.csdn.net/weixin_41500849/article/details/80246221 写在前面的话 本文主要内容是更换系统源为清华大学源,更换pyt ...
- The current .NET SDK does not support targeting .NET Core 3.0
编译错误 Severity Code Description Project File Line Suppression StateError NETSDK1045 The current .NET ...
- Github 下载项目的某一分支版本
参考:如何在 GitHub 下载某个程序的特定版本(代码)? 在安装ntf做int实验的时候,发现int demo的这个repo是该项目的一个branch,与master分支不一致(5 commits ...
- APP AutoTestCaseID
public class AutoTestCaseID { ElementExist el = new ElementExist(); static AutoTestExcelFile ft = ne ...
- PHP如何安装扩展
PHP如何安装扩展 一.总结 一句话总结:兩步: dll php.ini a.下载好扩展的dll,放入指定文件夹下 b.在php.ini配置文件中声明插件 1.什么是php扩展? php核心 不支持 ...
- 解决xshell乱码问题
如下图,xshell在执行命令时显示乱码 解决办法: 文件—属性—终端,将编码改成Unicode即可 参考文章 https://blog.csdn.net/yueloveme/article/deta ...