#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int route[25][5];
int flag[25];
int n;
int num[25];
int Sum;
void DFS(int n1,int sum)
{
int i,j;
if(sum==19)
{
for(j=1;j<=3;j++)
{
if(route[n1][j]==n)
{
printf("%d: %d",++Sum,n);
for(i=0;i<=18;i++)
{
printf(" %d",num[i]);
}
printf(" %d\n",n);
break;
}
}
return ;
}
for(i=1;i<=3;i++)
{
if(flag[route[n1][i]]==0)
{
flag[route[n1][i]]=1;
num[sum]=route[n1][i];
DFS(route[n1][i],sum+1);
flag[route[n1][i]]=0;
}
}
}
int main()
{
int i,j,m;
for(i=1;i<=20;i++)
{
for(j=1;j<=3;j++)
scanf("%d",&route[i][j]);
sort(route[i]+1,route[i]+4);
}
while(scanf("%d",&n)&&n!=0)
{
Sum=0;
memset(flag,0,sizeof(flag));
flag[n]=1;
m=n;
DFS(m,0);
}
return 0;
}
杭电2181
最新推荐文章于 2021-03-27 10:37:42 发布