这样点双的写法WA 3 4 7?
查看原帖
这样点双的写法WA 3 4 7?
575363
revolutionary_oier楼主2024/9/30 18:24
#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn=2e3+10;
int n,m,cnt,root,tt,k,tot;
int head[maxn],dfn[maxn],low[maxn],sz[maxn];
bool is[maxn];
struct node{
	int u,v,nxt;
}e[maxn];
inline void add(int u,int v){
	e[++cnt].u=u;
	e[cnt].v=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
inline void ipt(){
	cnt=n=tt=tot=0;
	for(int i=1;i<=1000;i++)head[i]=0;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%lld%lld",&u,&v);
		n=max(n,max(u,v));
		add(u,v);
		add(v,u);
	}
	for(int i=1;i<=2000;i++)dfn[i]=low[i]=sz[i]=0,is[i]=false;
}
stack<int>s;
inline void tarjan(int u,int fa){
	dfn[u]=low[u]=++tt;
	s.push(u);
	if(u==root&&!head[u]){
		is[u]=true;
		return ;
	}
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].v;
		if(v==fa)continue;
		if(!dfn[v]){
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u]){
				is[u]=true;
				++tot;
				int ct=1;
				while(1){
					int x=s.top();
					s.pop();
					if(!is[x])sz[tot]++;
					else ++ct;
					if(x==v)break;
				}
				if(ct>1){
					sz[tot]=0;
					--tot;
				}
			}
		}
		else low[u]=min(low[u],dfn[v]);
	}
}
inline void solve(){
	root=1;
	tarjan(1,1);
	int ans=1;
	for(int i=1;i<=tot;i++)ans*=sz[i];
	printf("Case %lld: %lld %lld\n",k,tot,ans);
}
signed main(){
	while(1){
		++k;
		scanf("%lld",&m);
		if(m==0)return 0;
		ipt();
		solve();
	}
	return 0;
}
2024/9/30 18:24
加载中...