Test

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#define MAXN 0x7fffffff
typedef long long LL;
const int N=1005;
using namespace std;
inline int Getint(){register int x=0,f=1;register char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}return x*f;}
struct node{int to,next;}g[N*N];
int h[N],cnt,num[N];
void AddEdge(int x,int y){
	num[x]++,num[y]++;
	g[++cnt].to=y,g[cnt].next=h[x],h[x]=cnt;
	g[++cnt].to=x,g[cnt].next=h[y],h[y]=cnt;
}
bool vis[N];int chk;
void Dfs(int x){
	vis[x]=1;
	chk+=num[x]&1;
	for(int i=h[x];i;i=g[i].next){
		int to=g[i].to;
		if(!vis[to])Dfs(to);
	}
}
int main(){
	int T=0;
//	freopen("rand.txt","r",stdin);
	while(1){
		int n=Getint(),m=Getint(),t=Getint();
		if(n==0&&m==0&&t==0)break;
		memset(h,0,sizeof(h));cnt=0;
		memset(vis,0,sizeof(vis));
		memset(num,0,sizeof(num));
		for(int i=1;i<=m;i++)
		{
			int x=Getint(),y=Getint();
			AddEdge(x,y);
		}
		int ans=m;
		for(int i=1;i<=n;i++)
		{
			if(!vis[i]&&h[i])
			{
				chk=0,Dfs(i);
				ans++;
				if(chk>2)ans+=(chk-2)/2;
			}
		}
		if(ans>m)ans--;
		printf("Case %d: %d\n",++T,ans*t);
	}
	return 0;
}
#include<iostream>
using namespace std;
void Dfs(int x){
	lowlink[x]=dfn[x]=++sign;
	Stack[++Cnt]=x;instack[x]=true;
	for(int i=h[x];i;i=g[i].next){
		int to=g[i].to;
		if(!dfn[to]){
			Dfs(to);
			lowlink[x]=min(lowlink[x],lowlink[to]);
		}else if(instack[to])lowlink[x]=min(lowlink[x],dfn[to]);
	}
	if(lowlink[x]==dfn[x]){
		SCC++;
		int t;
		do{
			t=Stack[Cnt--];
			belong[t]=SCC;
			instack[t]=false;
		}while(t!=x);
	}
}
int main(){
	
	return 0;
}
void Dfs(int x){
	lowlink[x]=dfn[x]=++sign;
	Stack[++Cnt]=x;instack[x]=true;
	for(int i=h[x];i;i=g[i].next){
		int to=g[i].to;
		if(!dfn[to]){
			Dfs(to);
			lowlink[x]=min(lowlink[x],lowlink[to]);
		}else if(instack[to])lowlink[x]=min(lowlink[x],dfn[to]);
	}
	if(lowlink[x]==dfn[x]){
		SCC++;
		int t;
		do{
			t=Stack[Cnt--];
			belong[t]=SCC;
			instack[t]=false;
		}while(t!=x);
	}
}
posted @ 2020-11-02 14:53  Emiya_2020  阅读(99)  评论(0编辑  收藏  举报