Danut grew up in a city called Bucharest. When he got to the 7th grade he realized that Bucharest is a really weird city: it has 2N intersections, each intersection numbered with a unique number between 0 and 2N-1 (inclusive). Also, it seems that the former mayors were computer scientists because they built streets only between two intersections for which, when written in base 2, the associated numbers differ by only one digit. E.g., there is a street connecting intersections (10) and 3 (11) or 5 (0101) and 13 (1101), but there is no street connecting intersections 4 (0100) and 9 (1001) or 11 (01011) and 17 (10001).
Furthermore, the streets themselves were also numbered: if there is a street between intersections X and Y, then it is numbered as log2|X-Y|. Warning! Each street will always be numbered with an integer, and more than one street may have the same number. E.g. the street connecting intersections 5 and 13 will be numbered as 3 (log2|5-13| = log28 = 3).
Because he can't sleep, Danut thinks about two intersections every night and wants to find all the disjoint paths that connect them. Please help him get over his insomnia.
Given M pairs of intersections determine all the disjoint paths between the two intersections in each pair.
Input file metro.in will contain:
Output file metro.out will contain for each pair Ai, Bi given in the input file a number Ki, representing the number of disjoint paths between intersections Ai, Bi, and on the following Ki lines it will display one path from Ai to Bi. For each path it will display the numbers of the streets visited while traveling from intersection Ai to intersection Bi. The numbers of the streets on the same path will be separated by a space.
metro.in | metro.out | Explanation |
3 1 5 3 |
3 0 2 1 0 1 2 2 1 |
The number of intersections in Bucharest is 23 = 8. Only one pair (5, 3) was specified in the input file. From 5 to 3 there are three paths that satisfy the conditions of the task: 5 4 0 2 3 5 7 3 5 1 3 |
Time limit: 0.2 seconds/test
Alexandru Mosoi
http://mosoi.lumina.ro
Politehnica University of Bucharest
Contact: alexandru.mosoi # gmail.com