hdoj 3844 Mining Your Own Business 【在无向图选择尽量少的点涂黑,使得任意删除一个点后每个BCC里面至少有一个点涂黑】
来源:互联网 发布:vb循环语句for next 编辑:程序博客网 时间:2024/05/01 00:56
Mining Your Own Business
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1701 Accepted Submission(s): 271
Problem Description
John Digger is the owner of a large illudium phosdex mine. The mine is made up of a series of tunnels that meet at various large junctions. Unlike some owners, Digger actually cares about the welfare of his workers and has a concern about the layout of the mine. Specifically, he worries that there may a junction which, in case of collapse, will cut off workers in one section of the mine from other workers (illudium phosdex, as you know, is highly unstable). To counter this, he wants to install special escape shafts from the junctions to the surface. He could install one escape shaft at each junction, but Digger doesn’t care about his workers that much. Instead, he wants to install the minimum number of escape shafts so that if any of the junctions collapses, all the workers who survive the junction collapse will have a path to the surface.
Write a program to calculate the minimum number of escape shafts and the total number of ways in which this minimum number of escape shafts can be installed.
Write a program to calculate the minimum number of escape shafts and the total number of ways in which this minimum number of escape shafts can be installed.
Input
The input consists of several test cases. The first line of each case contains a positive integer N (N <= 5×10^4) indicating the number of mine tunnels. Following this are N lines each containing two distinct integers s and t, where s and t are junction numbers. Junctions are numbered consecutively starting at 1. Each pair of junctions is joined by at most a single tunnel. Each set of mine tunnels forms one connected unit (that is, you can get from any one junction to any other).
The last test case is followed by a line containing a single zero.
The last test case is followed by a line containing a single zero.
Output
For each test case, display its case number followed by the minimum number of escape shafts needed for the system of mine tunnels and the total number of ways these escape shafts can be installed. You may assume that the result fits in a signed 64-bit integer.
Follow the format of the sample output.
Follow the format of the sample output.
Sample Input
91 34 13 51 22 61 56 31 63 261 21 32 42 53 63 70
Sample Output
Case 1: 2 4Case 2: 4 1
RE到死。。。。
题意就不说了吧
思路
转化模型:在一个无向图上选择尽量少的点涂黑,使得任意删除一个点后,每个BCC至少有一个点涂黑。
则有:当一个BCC只有一个割顶时才需要涂色,而且是任意选择一个非割顶涂色。特别地,当图是连通的,最少涂色两个点,且方案数为V * ( V - 1 ) / 2 其中V为点数。
AC代码:注意预处理栈大小 用C++提交
本题有10W个点。。。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <cstring>#include <vector>#include <stack>#include <queue>#include <algorithm>#define LL long long #define MAXN 100000+100#define MAXM 200000+100#define INF 10000000using namespace std;struct Edge{int from, to;};stack<Edge> S;//存储BCC里面的边 vector<int> G[MAXN], bcc[MAXN];//G存储图 bcc存储BCC里所有点 int low[MAXN], dfn[MAXN];int dfs_clock;bool iscut[MAXN];//标记割点int bccno[MAXN], bcc_cnt;//bccno[i]表示i属于哪个BCC bcc_cnt是BCC计数器 int k = 1;int right;//最大连接点编号 void init(){for(int i = 1; i < MAXN; i++)G[i].clear();}void getMap(int M){int s, t;right = 0;while(M--){scanf("%d%d", &s, &t);G[s].push_back(t);G[t].push_back(s);right = max(max(s, t), right);}}void tarjan(int u, int fa){low[u] = dfn[u] = ++dfs_clock;int child = 0;//计算子节点数目for(int i = 0; i < G[u].size(); i++){int v = G[u][i];Edge E = {u, v};if(!dfn[v]){S.push(E);child++;tarjan(v, u);low[u] = min(low[u], low[v]);if(low[v] >= dfn[u]){iscut[u] = true;//割点 bcc_cnt++;bcc[bcc_cnt].clear();for(;;){ Edge x = S.top();S.pop();if(bccno[x.from] != bcc_cnt){bcc[bcc_cnt].push_back(x.from);bccno[x.from] = bcc_cnt;}if(bccno[x.to] != bcc_cnt){bcc[bcc_cnt].push_back(x.to);bccno[x.to] = bcc_cnt;}if(x.from == u && x.to == v) break;}}}else if(dfn[v] < dfn[u] && v != fa){S.push(E);low[u] = min(low[u], dfn[v]);}}if(fa < 0 && child == 1) iscut[u] = false; }void find_cut(int l, int r){memset(bccno, 0, sizeof(bccno));memset(iscut, false, sizeof(iscut));memset(low, 0, sizeof(low));memset(dfn, 0, sizeof(dfn));dfs_clock = bcc_cnt = 0;for(int i = l; i <= r; i++)if(!dfn[i]) tarjan(i, -1);}void solve(){LL ans = 0, sum = 1;//ans 表示最少需要的太平井数目 sum表示方案数LL cut_cnt;//统计每个BCC里面的割点数目 for(int i = 1; i <= bcc_cnt; i++){cut_cnt = 0; for(int j = 0; j < bcc[i].size(); j++)if(iscut[bcc[i][j]]) cut_cnt++;if(cut_cnt == 1){ans++; sum *= (LL)bcc[i].size() - cut_cnt; }} if(bcc_cnt == 1)//图是连通的{LL t = bcc[1].size();//坑死啊 100000个点 还需要用LL ans = 2;//至少需要两个太平井 sum = (t - 1) * t / 2;} printf("Case %d: %lld %lld\n", k++, ans, sum);}int main(){int m;while(scanf("%d", &m), m){init();getMap(m);find_cut(1, right);//连接点是从1开始的 solve();}return 0;}
0 0
- hdoj 3844 Mining Your Own Business 【在无向图选择尽量少的点涂黑,使得任意删除一个点后每个BCC里面至少有一个点涂黑】
- 给你一个 n 个点,m 条边的无向图,求至少要在这个的基础上加多少条无向边使得任意两个点可达~
- Mining Your Own Business(点双联通)
- HDU -- 3844 Mining Your Own Business(点双连通)
- 无向图 点连通tarjan算法 求割点 + 求BCC以及BCC里面的点 + 求去掉每个点后图中BCC数目 【总结】
- 无向图 点连通tarjan算法 求割点 + 求BCC以及BCC里面的点 + 求去掉每个点后图中BCC数目 【总结】
- poj 2117 Electricity 【无向图求割点】【求去掉一个点后 图中最多的BCC数目】
- UVALive 5135 - Mining Your Own Business(点双连通)
- Uva Mining Your Own Business(点双连通分量)
- Mining Your Own Business 点双连通分量
- hdu 3844 Mining Your Own Business (点双连通分量)
- UVALive5135 - Mining Your Own Business(BCC)
- hdu3844 Mining Your Own Business,无向图的双连通分量
- POJ 1523--SPF【无向图的所有割点 && 删去该点后bcc的数目】
- 【UVALive】5135 Mining Your Own Business 点双连通+割顶
- LA 5135 Mining Your Own Business(点双连通分量+贪心)
- UVAlive 5135 Mining Your Own Business [点双连通分量] [求割顶]
- UVALive 5135 Mining Your Own Business(点双连通分量)
- 优化临时表使用,SQL语句性能提升100倍
- 面向对象与面向过程
- Android报错记录
- 轻量级框架和重量级框架
- Android中WindowManager.LayoutParams类详解
- hdoj 3844 Mining Your Own Business 【在无向图选择尽量少的点涂黑,使得任意删除一个点后每个BCC里面至少有一个点涂黑】
- UVA 10970 Big Chocolate
- JAVA -- arraylist 容量
- Matlab
- acm CodeForces 554B
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- python 读写excel表格
- TDBGrid增加鼠标滚动事件
- 【工作日志】【asp】【03】iis配置好后要改动的几个地方