#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
#define maxn 21
#define INF 0xfffffff
using namespace std;
bool map[maxn][maxn];
bool used[maxn];
int res[maxn];
int num;
int cas;
void init()
{
int a, b, c, i;
for (i = 1; i <= 20; i++) {
scanf("%d%d%d", &a, &b, &c);
map[i][a] = true;
map[i][b] = true;
map[i][c] = true;
}
}
void dfs(int dep, int count)
{
int i, j;
res[count] = dep;
if (count == 19) {
if (map[dep][cas]) {
printf("%d: ", ++num);
for (i = 0; i < 20; ++i)
printf("%d ", res[i]);
printf("%d\n", res[0]);
}
return;
}
for (j = 1; j <= 20; j++) {
if (map[dep][j] && !used[j]) {
used[j] = true;
dfs(j, count + 1);
used[j] = false;
}
}
}
int main()
{
memset(map, 0, sizeof(map));
init();
while (scanf("%d",&cas),cas)
{
num = 0;
memset(used, false, sizeof(used));
memset(res, 0, sizeof(res));
used[cas] = true;
dfs(cas, 0);
}
return 0;
}
05-21
497
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交