90pts求助
查看原帖
90pts求助
285617
黑影洞人楼主2022/7/23 13:01
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#define int long long
#define N 2007
using namespace std;
int head[N],to[N],nxt[N],dfn[N],low[N],cnt,tot,st[N],top,bcc;
bool cut[N];
int n,m,tott;
vector<int>g[N];
void csh(){
	tot=cnt=top=n=0;
	memset(dfn,0,sizeof(dfn));
	memset(cut,0,sizeof(cnt));
	memset(st,0,sizeof(st));
	//memset(g,0,sizeof(g));
	for(int i=1;i<=bcc;i++)g[i].clear();
	bcc=0;
	memset(head,0,sizeof(head));
	memset(to,0,sizeof(to));
	memset(nxt,0,sizeof(nxt));
}
void add(int u,int v){
	to[++tot]=v;
	nxt[tot]=head[u];
	head[u]=tot;
}
void tarjan(int x){
	dfn[x]=low[x]=++cnt;
	st[++top]=x;
	int son=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(!dfn[y]){
			tarjan(y);
			low[x]=min(low[x],low[y]);
			if(low[y]>=dfn[x]){
				son++;
				if(x!=1||son>1)cut[x]=1;
				g[++bcc].push_back(x);
				while(st[top+1]!=y)g[bcc].push_back(st[top--]);
			}
		}else low[x]=min(low[x],dfn[y]);
	}
	//if(son==0&&fa==0)cut[x]=0,g[++bcc].push_back(x);
}
signed main(){
	while(scanf("%lld",&m)&&m){
		++tott;
		csh();
		for(int i=1;i<=m;i++){
			int a,b;
			scanf("%lld%lld",&a,&b);
			add(a,b);add(b,a);
			n=max(n,max(a,b));
		}
		tarjan(1);
		int ck=0,fas=1;
		for(int i=1;i<=bcc;i++){
			int siz=g[i].size(),ct=0;
			for(int j=0;j<siz;j++)ct+=cut[g[i][j]];
			//if(ct>1)continue;
			if(ct==1)ck++,fas*=siz-1;
			if(ct==0)ck+=2,fas*=(siz*siz-siz)>>1;
		}
		printf("Case %lld: %lld %lld\n",tott,ck,fas);
	}
	return 0;
}



2022/7/23 13:01
加载中...