1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include<iostream> #include<cstdio> #include<vector> #include<cstring> using namespace std; long long read() { long long x=0,f=1; char c=getchar(); while(!isdigit(c)){if(c=='-') f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } const int N=2*500+20; vector <int> e[N],e2[N]; int n,m; int dfn[N],low[N],dfn_to,mstack[N],top,cnt,size[N]; bool vis[N]; void Tarjan(int now,int father) { vis[now]=true; low[now]=dfn[now]=++dfn_to; mstack[++top]=now; for(int i=0;i<int(e[now].size());i++) if(vis[e[now][i]]==false) { Tarjan(e[now][i],now); low[now]=min(low[now],low[e[now][i]]); if(low[e[now][i]] >= dfn[now]) { e2[now].push_back(n+ ++cnt); size[cnt]=1; while(mstack[top+1]!=e[now][i]) e2[n+cnt].push_back(mstack[top--]), size[cnt]++; } } else if(e[now][i]!=father) low[now]=min(low[now],dfn[e[now][i]]); } long long ans,ans2; int dfs(int now) { int t_cnt=(now>n); for(int i=0;i<int(e2[now].size());i++) t_cnt+=dfs(e2[now][i]); if(now>n and t_cnt==1) ans2++,ans*=(size[now-n]-1); return t_cnt; } bool Check() { int x=e2[1][0],t_cnt=0; for(int i=0;i<int(e2[x].size());i++) if(e2[e2[x][i]].size()!=0) t_cnt++; return t_cnt==1; } int main() { for(int o=1;;o++) { m=read(); if(m==0) break; for(int i=1;i<=500*2+5;i++) e[i].clear(),e2[i].clear(); dfn_to=cnt=0; memset(vis,0,sizeof vis);
n=0; for(int i=1;i<=m;i++) { int s=read(),t=read(); e[s].push_back(t); e[t].push_back(s); n=max(max(n,s),t); }
Tarjan(1,0); ans=1,ans2=0; dfs(1); if(e2[1].size()==1 and Check()==true) ans*=(size[e2[1][0]-n]-1), ans2++; if(cnt==1) ans=(n*(n-1))/2,ans2=2;
printf("Case %d: %lld %lld\n",o,ans2,ans); } return 0; }
|