标签:ret ems 欧拉 cas 连通 答案 include 连通块 逆序
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int edge[55][55],d[55];
void dfs(int mid) //寻找连通块
{
for(int k=1;k<=50;k++)
{
if(edge[mid][k])
{
edge[mid][k]--;
edge[k][mid]--;
dfs(k);
printf("%d %d\n",k,mid); //一定要逆序输出,这样得到的才是答案
}
}
return;
}
int main(void)
{
int t,n,t0,i,j,x,y;
scanf("%d",&t);
for(t0=1;t0<=t;t0++)
{
memset(edge,0,sizeof(edge));
memset(d,0,sizeof(d));
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
edge[x][y]++;
edge[y][x]++;
d[x]++;
d[y]++;
}
printf("Case #%d\n",t0);
for(i=1;i<=50;i++)
{
if(d[i]%2)
break;
}
if(i<=50)
printf("some beads may be lost\n");
else
{
for(j=1;j<=50;j++)
dfs(j);
}
if(t0!=t)
printf("\n");
}
}
标签:ret ems 欧拉 cas 连通 答案 include 连通块 逆序
原文地址:https://www.cnblogs.com/transcendent-heming/p/11747133.html