2015
04-13

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 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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define maxn 100005
#define MAXN 100005
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int n,m,cnt,tot,flag;
int lev,bcccnt;
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];

{
cnt++;
edge[cnt].v=v;
edge[cnt].w=w;
}
void Tarjan(int u,int pre)
{
int i,j,t,v,num=0;
low[u]=dfn[u]=++lev;
{
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;
for(i=1; i<=m; i++)  // 建图
{
scanf("%d%d",&u,&v);
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;
}

,
1. 5.1处，反了；“上一个操作符的优先级比操作符ch的优先级大，或栈是空的就入栈。”如代码所述，应为“上一个操作符的优先级比操作符ch的优先级小，或栈是空的就入栈。”

2. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;