Suppose we have a graph as shown below. This graph is a Peterson diagram. Vertices are numbered from 0 to 9. Each vertex has some letters. Consider a walk W on this graph using L vertices. When the letter sequence in walking W is the same as S, the string S is realized by walking W. We can visit a vertex multiple times.
For example, a string S is similar to "ABBECCD", which is implemented by walking (0, 1, 6, 9, 7, 2, 3). Our task is to find such a walk and, if such a walk exists, find the lexicographically smallest walk. If there is no such walk, -1 is returned.
petersonGraphWalk(S, v) -The Chinese translation of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
1 |
|
The above is the detailed content of Peterson diagram problem in C program. For more information, please follow other related articles on the PHP Chinese website!