/***********************************************************
euler.c -- 一筆書き
***********************************************************/
Declare Function scanf CDECl Lib"msvcrt" (fmt As *Byte, ...) As Long
Declare Function printf CDECl Lib"msvcrt" (fmt As *Byte, ...) As Long

#console

Const NMAX = 100 /* 点の数の上限 */
Const EDGEMAX = 100 /* 線の数の上限 */
Dim adjacent[NMAX,NMAX] As Long /* 隣接行列 */
Dim position[EDGEMAX + 1] As Long
Dim n As Long , n_edge As Long, edge As Long, solution As Long /* 点, 線の数; 線, 解の番号 */

Dim rr As Long

Sub readgraph() /* データ入力 */
Dim i As Long , j As Long

rr = scanf(Ex"%d%*[^\n]", VarPtr(n))

If rr <> 1 or n > NMAX Then /* 点の数 */
n = 0
Exit Sub
End If

While (scanf(Ex"%d%d%*[^\n]", VarPtr(i), VarPtr(j)) = 2)
n_edge++ /* 線の数 */
adjacent[i,j]++
adjacent[j,i]++ /* 有向グラフならこの行は削除 */
Wend

printf(Ex"隣接行列:\n")
For i=1 to n : For j=1 to n
printf(" %d", adjacent[i,j])
Next
printf(Ex"\n")
Next
End Sub

Sub visit(i As Long)
Dim j As Long

position[edge] = i
if (edge = n_edge) then
printf("解 %d: ", ++solution)
For i=0 To n: printf(" %d", position[i]): Next
printf("\n")
Else
For j=1 To n :if (adjacent[i,j]) Then

adjacent[i,j]--
adjacent[j,i]-- /* 有向グラフならこの行は削除 */
edge++: visit(j): edge--
adjacent[i,j]++
adjacent[j,i]++ /* 有向グラフならこの行は削除 */
End If
Next
End If
End Sub


readgraph() /* データを読む */
solution = 0:edge = 0: visit(1) /* 点1から出発 */
if (solution = 0) then printf(Ex"解なし\n")
Dim wa$
Input wa$
End