#include<bits/stdc++.h>
using namespace std;
#define mxn 510
struct E{
int from,to;
};
int dfn[mxn],iscut[mxn],bccno[mxn];
int step,bcc_cnt;
vector<int> v[mxn],bcc[mxn];
stack<E> s;
int dfs(int u,int fa){
int lowu=dfn[u]=++step;
int child=0;
for(int i=0;i<v[u].size();i++){
int to=v[u][i];
E e=(E){u,to};
if(!dfn[to]){
s.push(e);child++;
int lowv=dfs(to,u);
lowu=min(lowu,lowv);
if(lowv>=dfn[u]){
iscut[u]=1;
++bcc_cnt;
bcc[bcc_cnt].clear();
while(1){
E 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==to)break;
}
}
}
else if(dfn[to]<dfn[u]&&to!=fa)lowu=min(lowu,dfn[to]),s.push(e);
}
if(fa<0&&child==1)iscut[u]=0;
return lowu;
}
void init(){
memset(bccno,0,sizeof(bccno));
memset(dfn,0,sizeof(dfn));
memset(iscut,0,sizeof(iscut));
for(int i=1;i<mxn;i++)
v[i].clear();
step=bcc_cnt=0;
}
void bcc_do(int t){
for(int i=1;i<=t;i++)
if(!dfn[i])dfs(i,-1);
}
int main(){
int n,k=0;
while(scanf("%d",&n)&&n){
init();int t=0;k++;
while(n--){
int a,b;
scanf("%d%d",&a,&b);
t=max(t,a);t=max(t,b);
v[a].push_back(b);
v[b].push_back(a);
}
bcc_do(t);
long long ans1=0,ans2=1;
for(int i=1;i<=bcc_cnt;i++){
int c=0;
for(int j=0;j<bcc[i].size();j++)
if(iscut[bcc[i][j]])c++;
if(c==1){
ans1++;
ans2*=bcc[i].size()-1;
}
}
if(bcc_cnt==1){
ans1=2;ans2=bcc[1].size()*(bcc[1].size()-1)/2;
}
printf("Case %d: %lld %lld\n",k,ans1,ans2);
}
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)