hdu 3844 Mining Your Own Business (點雙連通分量)

來源:互聯網
上載者:User

標籤:des   style   http   color   io   os   java   ar   strong   

Mining Your Own BusinessTime Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1392    Accepted Submission(s): 219

Problem DescriptionJohn 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 
題意:給你一個圖,將上面一些點塗黑,使得去掉一個圖中一個點之後每一個點都能到達一個黑點,求出最小放的點數以及方案數。
思路:一個點雙連通分量中,如果只有一個點為割點,那麼這個分量必須在非割點的位置塗黑。問題就變為求解點雙連通分量了。有一種特殊情況是,全圖為一個分量,那麼需任意塗兩個點。
代碼:
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#define maxn 100005#define MAXN 100005#define INF 0x3f3f3f3f#pragma comment (linker,"/STACK:102400000,102400000")typedef long long ll;using namespace std;int n,m,cnt,tot,flag;int lev,bcccnt;int head[maxn];int dfn[maxn],low[maxn];bool vis[maxn],ok[maxn];struct Node{    int v,w,next;} edge[MAXN];int stau[maxn],stav[maxn],top,bccno[maxn];vector<int>bcc[maxn];void addedge(int u,int v,int w){    cnt++;    edge[cnt].v=v;    edge[cnt].w=w;    edge[cnt].next=head[u];    head[u]=cnt;}void Tarjan(int u,int pre){    int i,j,t,v,num=0;    low[u]=dfn[u]=++lev;    for(i=head[u];i;i=edge[i].next)    {        v=edge[i].v;        if(vis[v])        {            if(v!=pre) low[u]=min(low[u],dfn[v]);  // 橋不能用父親來更新 割點隨意        }        else        {            vis[v]=1;            top++;            stau[top]=u; stav[top]=v;            num++;            Tarjan(v,u);            if(dfn[u]<=low[v])            {                if(pre!=0) ok[u]=1;  // 不是根                bcccnt++;                bcc[bcccnt].clear();                while(!(stau[top]==u&&stav[top]==v))                {                    if(bccno[stav[top]]!=bcccnt) bccno[stav[top]]=bcccnt,bcc[bcccnt].push_back(stav[top]);                    if(bccno[stau[top]]!=bcccnt) bccno[stau[top]]=bcccnt,bcc[bcccnt].push_back(stau[top]);                    top--;                }                if(bccno[stav[top]]!=bcccnt) bccno[stav[top]]=bcccnt,bcc[bcccnt].push_back(stav[top]);                if(bccno[stau[top]]!=bcccnt) bccno[stau[top]]=bcccnt,bcc[bcccnt].push_back(stau[top]);                top--;            }            low[u]=min(low[u],low[v]);        }    }    if(pre==0&&num>1) ok[u]=1;}int main(){    int i,j,t,u,v,w,ca=0;    while(scanf("%d",&m),m)    {        cnt=n=0;        memset(head,0,sizeof(head));        for(i=1; i<=m; i++)  // 建圖        {            scanf("%d%d",&u,&v);            addedge(u,v,0);            addedge(v,u,0);            n=max(n,u);            n=max(n,v);        }        memset(vis,0,sizeof(vis));        memset(ok,0,sizeof(ok));        memset(bccno,0,sizeof(bccno));        bcccnt=0;        for(i=1; i<=n; i++)// 割點或者橋的求解        {            if(vis[i]) continue ;            lev=0;            vis[i]=1;            top=0;            Tarjan(i,0);        }        ll ans=0,res=1;        for(i=1;i<=bcccnt;i++)        {            int num=0;            for(j=0;j<bcc[i].size();j++)            {                if(ok[bcc[i][j]]) num++;            }            if(num==1)            {                ans++; res*=(bcc[i].size()-1);            }        }        if(bcccnt==1)        {            ans=2; res=ll(n)*ll(n-1)/2;        }        printf("Case %d: %I64d %I64d\n",++ca,ans,res);    }    return 0;}

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.