P3533 [POI 2012] RAN-Rendezvous
Description
Byteasar is a ranger who works in the Arrow Cave - a famous rendezvous destination among lovers.
The cave consists of $n$ chambers connected with one-way corridors.
In each chamber exactly one outgoing corridor is marked with an arrow.
Every corridor leads directly to some (not necessarily different) chamber.
The enamoured couples that agree to meet in the Arrow Cave are notorious for forgetting to agree upon specific chamber, and consequently often cannot find their dates.
In the past this led to many mix-ups and misunderstandings\dots But ever since each chamber is equipped with an emergency telephone line to the ranger on duty, helping the enamoured find their dates has become the rangers' main occupation.
The rangers came up with the following method.
Knowing where the enamoured are, they tell each of them how many times they should follow the corridor marked with an arrow in order to meet their date.
The lovers obviously want to meet as soon as possible - after all, they came to the cave to spend time together, not to wander around alone!
Most rangers are happy to oblige: they do their best to give each couple a valid pair of numbers such that their maximum is minimal.
But some rangers, among their numbers Byteasar, grew tired of this extracurricular activity and ensuing puzzles. Byteasar has asked you to write a program that will ease the process. The program, given a description of the cave and the current location of $k$ couples, should determine $k$ pairs of numbers $x_i$ and $y_i$ such that if the $i$-th couple follows respectively: he $x_i$ and she $y_i$ corridors marked with arrows,then they will meet in a single chamber of the cave $max(x_i,y_i)$ is minimal,subject to above $min(x_i,y_i)$ is minimal,if above conditions do not determine a unique solution, then the woman should cover smaller distance ($x_i\ge y_i$).
It may happen that such numbers $x_i$ and $y_i$ do not exist - then let $x_i=y_i=-1$. Note that it is fine for several couples to meet in a single chamber. Once the lovers have found their dates, they will be happy to lose themselves in the cave again...
Input Format
N/A
Output Format
N/A