SGU link is here
Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The blocks usually are called bones, dominoes, or pieces and sometimes men, stones, or even cards. The face of each piece is divided, by a line or ridge, into two squares, each of which is marked as would be a pair of dice...
The principle in nearly all modern dominoes games is to match one end of a piece to another that is identically or reciprocally numbered.
Given a set of domino pieces where each side is marked with two digits from 0 to 6. Your task is to arrange pieces in a line such way, that they touch through equal marked sides. It is possible to rotate pieces changing left and right side.
The first line of the input contains a single integer N (1 ≤ N ≤ 100) representing the total number of pieces in the domino set. The following N lines describe pieces. Each piece is represented on a separate line in a form of two digits from 0 to 6 separated by a space.
Write “No solution” if it is impossible to arrange them described way. If it is possible, write any of way. Pieces must be written in left-to-right order. Every of N lines must contains number of current domino piece and sign “+” or “-“ (first means that you not rotate that piece, and second if you rotate it).
We only need to find the Euler path. Every domino is an edge. The vertices are 1~7.
Fleury’s Algorithm (Euler trial)
Let $G$ be a connected graph. If $G$ is Eulerian then Fleury's Algorithm will produce an Eulerian trial in $G$.
In a connected graph $G$, a bridge is an edge which, if removed, produces a disconnected graph.
Choose any vertex $v$ of $G$ and set current vertex equal to $v$ and current trail equal to the empty sequence of edges
Select any edge $e$ incident with the current vertex but choosing a bridge only if there is no alternative
Add $e$ to the current trail and set the current vertex equal to the vertex at the other end of $e$. if $e$ is a loop, the current vertex will not move
Delete $e$ from the graph. Delete any isolated vertices. Repeate steps 2 - 4 untill all edges have been deleted from $G$. The final current trail is an Eulerian trail in $G$