HDU 3844 Mining Your Own Business

來源:互聯網
上載者:User

標籤:

Mining Your Own BusinessTime Limit: 1000msMemory Limit: 32768KBThis 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. InputThe 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. OutputFor 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
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
Source2011WorldFinal 解題:點雙連通分量,當然我不是直接求點雙連通分量的,我是求割點。先找出割點,然後從非割點開始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 }
View Code

 

HDU 3844 Mining Your Own Business

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.