eolymp
bolt
Try our new interface for solving problems
Problems

Kingdom of Magic

Kingdom of Magic

Kingdom of Magic has a network of bidirectional magic portals between cities since ancient times. Each portal magically connects a pair of cities and allows fast magical communication and travel between them. Cities that are connected by the magic portal are called neighboring. Prince Albert and Princess Betty are living in the neighboring cities. Since their childhood Albert and Betty were always in touch with each other using magic communication Orbs, which work via a magic portal between the cities. Albert and Betty are in love with each other. Their love is so great that they cannot live a minute without each other. They always carry the Orbs with them, so that they can talk to each other at any time. There is something strange about their love - they have never seen each other and they even fear to be in the same city at the same time. People say that the magic of the Orbs have affected them. Traveling through the Kingdom is a complicated affair for Albert and Betty. They have to travel through magic portals, which is somewhat expensive even for royal families. They can simultaneously use a pair of the portals to move to a different pair of cities, or just one of them can use a portal, while the other one stays where he or she is. At any moment of their travel they have to be in a neighboring cities. They cannot simultaneously move through the same portal. Write a program that helps Albert and Betty travel from one pair of the cities to another pair. It has to find the cheapest travel plan - with the minimal number of times they have to move though the magic portals. When they move through the portals simultaneously it counts as two moves. \InputFile Input contains several datasets. The first line of each dataset contains integer numbers \textbf{n}, \textbf{m}, \textbf{a_1}, \textbf{b_1}, \textbf{a_2}, \textbf{b_2}. Here \textbf{n} (\textbf{3} ≤ \textbf{n} ≤ \textbf{100}) is a number of cities in the Kingdom (cities are numbered from \textbf{1} to \textbf{n}); \textbf{m} (\textbf{2} ≤ \textbf{m} ≤ \textbf{1000}) is a number of magic portals; \textbf{a_1},\textbf{b_1} (\textbf{1} ≤ \textbf{a_1}, \textbf{b_1} ≤ \textbf{n}, \textbf{a_1} ≠ \textbf{b_1}) are the neighboring cities where Albert and Betty correspondingly start their travel from; \textbf{a_2}, \textbf{b_2} (\textbf{1} ≤ \textbf{a_2}, \textbf{b_2} ≤ \textbf{n}, \textbf{a_2} ≠ \textbf{b_2}) are the neighboring cities where Albert and Betty correspondingly want to get to (\textbf{a_1} ≠ \textbf{a_2} or \textbf{b_1} ≠ \textbf{b_2}). Following \textbf{m} lines describe the portals. Each line contains two numbers \textbf{p_i1} and \textbf{p_i2} (\textbf{1} ≤ \textbf{p_i1}, \textbf{p_i2} ≤ \textbf{n}, \textbf{p_i1} ≠ \textbf{p_i2}) - cities that are connected by the portal. There is at most one portal connecting two cities. \OutputFile On the first line of the output for each test case write two numbers \textbf{c} and \textbf{k}. Here \textbf{c} is the minimal number of moves in the travel plan; \textbf{k} is the number of neighboring city pairs that Albert and Betty visit during their travel including \textbf{a_1}, \textbf{b_1} at the start and \textbf{a_2}, \textbf{b_2} at the end. Then write \textbf{k} lines with two integer numbers \textbf{a'}_i and \textbf{b'}_i on each line -- consecutive different pairs of neighboring cities that Albert and Betty visit during their travel. If there are multiple travel plans with the same number of moves, then write any of them. It is guaranteed that solution exists. Print a blank line between consecutive datasets.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4 5 1 2 2 1
1 2
2 3
3 4
4 1
1 3
Output example #1
3 3
1 2
1 3
2 1