记录编号 578445 评测结果 AAAAAAAAAA
题目名称 [HNOI 2012] 矿场搭建 最终得分 100
用户昵称 Gravatar遥时_彼方 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2023-03-17 19:27:28 内存使用 0.00 MiB
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
	int x=0;bool flag=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	if(flag) return x;
	return ~(x-1);
}
inline void write(int x)
{
	if(x<0) {x=~(x-1);putchar('-');}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
////////////////////////
const int N=350;
int nc; 
struct G
{
	int ar;
	int nx;
}a[N<<1];
int aj,mx;
int hd[N];
int ans1;
ull ans2;
int j[N];
int b[N];
ull dfs(int col,int x)
{
	j[x]=col;
	for(int i=hd[x];i;i=a[i].nx) if(!j[a[i].ar]) dfs(col,a[i].ar);
}
void solve(int x)
{
	int ot1=0;
	memset(j,0,sizeof(j));
	j[x]=999;
	rep(i,1,mx)
	{
		if(j[i]) continue;
		dfs(++ot1,i);
	}
	if(ot1>1) b[x]=1;
//	cout<<x<<":"<<ot1<<" "<<ot2<<" "<<mx<<endl;
}
inline void ADD(int x,int y)
{
	a[++aj].ar=y;
	a[aj].nx=hd[x];
	hd[x]=aj;
}
struct PD
{
	int p;
	int sz;
};
PD dfs2(int x)
{
	b[x]=2;
	PD re;
	re.p=0;
	re.sz=1;
	PD rt;
	for(int i=hd[x];i;i=a[i].nx)
	{
		if(b[a[i].ar]==1)
		{
			re.p+=1;
			b[a[i].ar]=3;
		} 
		if(b[a[i].ar]) continue;
		rt=dfs2(a[i].ar);
		re.p+=rt.p;
		re.sz+=rt.sz; 
//		cout<<"p3:"<<x<<" "<<re.p<<" "<<re.sz<<" "<<a[i].ar<<" "<<rt.p<<" "<<rt.sz<<endl;
	}
	return re;
}
int c[N];
int main()
{
    freopen("bzoj_2730.in","r",stdin);
	freopen("bzoj_2730.out","w",stdout);
	nc=read();
	int s1,s2;
	int s=0;
	PD s3;
	while(nc)
	{
		memset(a,0,sizeof(a));
		memset(hd,0,sizeof(hd));
		memset(b,0,sizeof(b));
		aj=mx=ans1=0;
		ans2=1;
		//清零 
		rep(i,1,nc) s1=read(),s2=read(),ADD(s1,s2),ADD(s2,s1),mx=max(mx,max(s1,s2));
		rep(i,1,mx) solve(i);
		rep(i,1,mx) c[i]=b[i]/*,cout<<"p1:"<<i<<" "<<b[i]<<endl*/;
		rep(i,1,mx) 
		{
			rep(o,1,mx) if(c[o]==1) b[o]=c[o];
		    if(b[i]) continue;
			s3=dfs2(i);
			if(s3.p>1) continue;
//			cout<<"p2 s3:"<<i<<" "<<s3.p<<" "<<s3.sz<<endl;
			ans1++;
			ans2*=s3.sz;
		}
		if(ans1==1) ans1=2,ans2=(ans2*(ans2-1))>>1;
		cout<<"Case "<<++s<<": "<<ans1<<" "<<ans2<<endl;
		nc=read(); 
	}
    return 0;
}