HDU 3844 Mining Your Own Business

Mining Your Own Business

Time Limit: 1000ms

Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 3844
64-bit integer IO format: %I64d      Java class name: Main

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.

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.

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.

Sample Input

9
1 3
4 1
3 5
1 2
2 6
1 5
6 3
1 6
3 2
6
1 2
1 3
2 4
2 5
3 6
3 7
0

Sample Output

Case 1: 2 4
Case 2: 4 1

Source

2011WorldFinal

解题:点双连通分量,当然我不是直接求点双连通分量的,我是求割点。先找出割点,然后从非割点开始dfs,在dfs的过程中,不能经过割点。

当一个点双连通分量中有且仅有一个割点的时候才选择一个位置进行安装,安装的可选的位置不包括割点。

当整个图不存在割点的时候,需要两个位置,因为如果一个,恰好放梯子的位置挂了,全挂了。所以随便选两个位置就好了。

此题目需要扩栈。。。。WF的题目满是坑

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 #pragma comment(linker, "/STACK:102400000,102400000")
 6 using namespace std;
 7 typedef long long LL;
 8 const int maxn = 50010;
 9 struct arc {
10     int to,next;
11     arc(int x = 0,int y = -1) {
12         to = x;
13         next = y;
14     }
15 } e[1000010];
16 int head[maxn],dfn[maxn],low[maxn],idx,tot,cn;
17 bool cut[maxn];
18 void add(int u,int v) {
19     e[tot] = arc(v,head[u]);
20     head[u] = tot++;
21     e[tot] = arc(u,head[v]);
22     head[v] = tot++;
23 }
24 void tarjan(int u,int fa) {
25     dfn[u] = low[u] = ++idx;
26     int son = 0;
27     for(int i = head[u]; ~i; i = e[i].next) {
28         if(e[i].to == fa) continue;
29         if(!dfn[e[i].to]) {
30             tarjan(e[i].to,u);
31             son++;
32             low[u] = min(low[u],low[e[i].to]);
33             if(fa != -1 && low[e[i].to] >= dfn[u] || fa == -1 && son > 1) {
34                 cut[u] = true;
35                 cn++;
36             }
37         } else low[u] = min(low[u],dfn[e[i].to]);
38     }
39 }
40 bool vis[maxn];
41 int cnt,n,m,cao;
42 bool fk[maxn];
43 void dfs(int u,int fa) {
44     vis[u] = true;
45     cnt++;
46     for(int i = head[u]; ~i; i = e[i].next) {
47         if(e[i].to == fa) continue;
48         if(cut[e[i].to]) {
49             if(!fk[e[i].to]) {
50                 cao++;
51                 fk[e[i].to] = true;
52             }
53             continue;
54         }
55         if(vis[e[i].to]) continue;
56         dfs(e[i].to,fa);
57     }
58 }
59 int main() {
60     int u,v,cs = 1;
61     while(scanf("%d",&m),m) {
62         memset(head,-1,sizeof head);
63         for(int i = tot = n = idx = cn = 0; i < m; ++i) {
64             scanf("%d%d",&u,&v);
65             add(u,v);
66             n = max(n,max(u,v));
67         }
68         memset(dfn,0,sizeof dfn);
69         memset(cut,false,sizeof cut);
70         for(int i = 1; i <= n; ++i)
71             if(!dfn[i]) tarjan(i,-1);
72         LL ret = 1;
73         if(!cn) printf("Case %d: %d %I64d\n",cs++,2,(LL)n*(n-1)/2);
74         else {
75             memset(vis,false,sizeof vis);
76             int ri = 0;
77             for(int i = 1; i <= n; ++i) {
78                 if(cut[i] || vis[i]) continue;
79                 cnt = cao = 0;
80                 memset(fk,false,sizeof fk);
81                 dfs(i,-1);
82                 if(cao < 2 && cnt) {ri++; ret *= cnt;}
83             }
84             printf("Case %d: %d %I64d\n",cs++,ri,ret);
85         }
86     }
87     return 0;
88 }

时间: 2024-10-12 15:01:37

HDU 3844 Mining Your Own Business的相关文章

hdu 3844 Mining Your Own Business (点双连通分量)

Mining Your Own Business Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1392    Accepted Submission(s): 219 Problem Description John Digger is the owner of a large illudium phosdex mine. The m

HDU 3844 Mining Your Own Business(割点,变形,开栈,经典)

题意:给出一个连通图,要求将某些点涂黑,使得无论哪个点(包括相关的边)撤掉后能够成功使得剩下的所有点能够到达任意一个涂黑的点,颜料不多,涂黑的点越少越好,并输出要涂几个点和有多少种涂法. 思路: 要使得任意撤掉一个点都能使其他点能够到达黑点,那么点双连通分量能保证这点,那么就在同个点双连通分量内涂黑1个点.但是每个[点双连通分量]都涂吗?太浪费颜料了,那就缩点成树,只需要涂叶子即可,那就找度为1的缩点.但是种数呢?叶子内的点除了割点外都是可以涂黑的,因为如果黑色割点被撤掉,那么叶子中的其他点怎么

UVA 1108 - Mining Your Own Business(双连通分量)

UVA 1108 - Mining Your Own Business 题目链接 题意:给定一个连通图,设置一个些安全点,使得其他任意一些节点崩塌后,其他点都能到一个安全点,问安全点最小数量和情况数 思路: #include <cstdio> #include <cstring> #include <vector> #include <stack> #include <map> using namespace std; const int N =

HDU 2448 Mining Station on the Sea 费用流

Mining Station on the Sea Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2123    Accepted Submission(s): 642 Problem Description The ocean is a treasure house of resources and the development o

HDU 2448 Mining Station on the Sea km

#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<map> using namespace std; const int maxn = 105; const int INF = (1<<30)-1; int g[2*maxn][2*maxn]; int f[2*maxn][2*maxn]; int lx[maxn],ly[ma

hdu 2448 Mining Station on the Sea【网络费用流】

Mining Station on the Sea Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2371    Accepted Submission(s): 732 Problem Description The ocean is a treasure house of resources and the development

HDU 2448 Mining Station on the Sea(最小费用流+spfa,超了n次的题)

Mining Station on the Sea Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2572    Accepted Submission(s): 775 Problem Description The ocean is a treasure house of resources and the development

UVALive - 5135 Mining Your Own Business(双连通分量)

题目大意:有N个矿井 ,由一些隧道连接起来,现在要修建尽量少的安全通道,使得无论哪里发生事故,所有人均能逃出,求建的最少的安全通道数量和方案数 解题思路:建安全通道的话,肯定不能建在割顶,因为割顶如果崩塌了,割顶所连接的双连通分量内的点就跑不掉了,还得在双连通分量里面再建点(上述为双连通分量内部只有一个割顶的情况),这样不划算,还不如直接在里面建点 如果一个双连通分量的内部割顶有多个的话,那么在这个双连通分量里面就可以不用建安全通道了,因为一个割顶崩塌了,还有其他点可以连向外面,所以,只考虑内部

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

题意:n条隧道由一些点连接而成,其中每条隧道链接两个连接点.任意两个连接点之间最多只有一条隧道.任务就是在这些连接点中,安装尽量少的太平井和逃生装置,使得不管哪个连接点倒塌,工人都能从其他太平井逃脱,求最少安装数量和方案. 思路:其实本题就相当于在一张无向图中,涂尽量少的黑点,使得任意删除哪个点,每个连通分量至少有一个黑点.因为不同的连通分量最多只有一个公共点,那一定是割点.可以发现,涂黑割点是不划算的,而且在 一个点-双连通分量中涂黑两个黑点也是不划算的.所以只有当点-双连通分量只有一个割点时