比赛 |
不准粘代码,必须自己写(HS除外) |
评测结果 |
AAAAAAAAAA |
题目名称 |
矿场搭建 |
最终得分 |
100 |
用户昵称 |
梦那边的美好ET |
运行时间 |
0.005 s |
代码语言 |
C++ |
内存使用 |
13.68 MiB |
提交时间 |
2019-09-29 22:28:25 |
显示代码纯文本
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN=501;
long long int ans=0,fanganshu=1;
int n,m,u,v,fenliangtot=0,casenum=0,zhan[MAXN],top=0,visit=0,dfn[MAXN],low[MAXN],root[MAXN],num[MAXN],roottot=0;
bool vis[MAXN];
struct fenliang{
int num,gediannum;
fenliang(){num=0;gediannum=0;}
}group[MAXN];
struct edge{
int v;
edge *NEXT;
edge() {v=0;NEXT=NULL;}
}*con[MAXN];
inline void ins(int start,int end){
edge *p=new(edge);
p->v=end;
p->NEXT=con[start];
con[start]=p;
}
inline void tarjan(int nv){
dfn[nv]=low[nv]=++visit;
for(edge *p=con[nv];p;p=p->NEXT){
int vv=p->v;
if(dfn[vv]==0){
tarjan(vv);
low[nv]=min(low[nv],low[vv]);
if(low[vv]>=dfn[nv])++num[nv];
}
else low[nv]=min(low[nv],dfn[vv]);
}
return;
}
void dfs(int nv){
vis[nv]=true;zhan[++top]=nv;
for(edge *p=con[nv];p;p=p->NEXT){
int vv=p->v;
if(vis[vv]==false){
dfs(vv);
if(low[vv]>=dfn[nv]){
++fenliangtot;
int place=zhan[top];
while(place!=nv){
--top;
if(num[place])++group[fenliangtot].gediannum;
else ++group[fenliangtot].num;
place=zhan[top];
}
if(num[place])++group[fenliangtot].gediannum;
else++group[fenliangtot].num;
}
}
}
return;
}
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
}
int main(){
freopen("bzoj_2730.in","r",stdin);
freopen("bzoj_2730.out","w",stdout);
while(1){
m=read();if(m==0)break;
memset(con,0,sizeof(con));
memset(dfn,0,sizeof(dfn));
memset(num,0,sizeof(num));
memset(vis,0,sizeof(vis));
memset(group,0,sizeof(group));
ans=n=roottot=fenliangtot=0;
fanganshu=1;
while(m--){
u=read();v=read();
n=max(n,max(u,v));
ins(u,v);ins(v,u);
}
for(int i=1;i<=n;++i)if(dfn[i]==0){root[++roottot]=i;tarjan(i);}
for(int i=1;i<=roottot;++i)if(num[root[i]]!=0)--num[root[i]];
for(int i=1;i<=n;++i)if(vis[i]==false)dfs(i);
for(int i=1;i<=fenliangtot;++i){
int a=group[i].num,b=group[i].gediannum;
if(b>=2)continue;
else if(b==1){++ans;fanganshu*=a;}
else if(b==0){ans+=2;fanganshu*=(a*(a-1)/2);}
}
printf("Case %d: %lld %lld\n",++casenum,ans,fanganshu);
}
return 0;
}