#P6348. [PA 2011] Journeys
[PA 2011] Journeys
Description
On a planet, there are countries and many bidirectional roads. The countries are numbered from to .
However, there are too many roads to describe in the usual way. So we describe the roads as follows: means that for any two countries , if and , then there is a road between and .
The capital is located in country . You want to know the minimum number of roads that must be taken to travel from country to any country. It is guaranteed that country can reach every country.
Input Format
The first line contains three integers .
Then follow lines, each containing four integers .
Output Format
Output lines. The -th line should contain the minimum number of roads that must be taken to travel from country to country .
5 3 4
1 2 4 5
5 5 4 4
1 1 3 3
1
1
2
0
1
Hint
For all testdata, it is guaranteed that , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号