#P4189. [CTSC2010] 星际旅行
[CTSC2010] 星际旅行
Description
In the year , the Earth Union has conquered planets in the Milky Way. For budget reasons, the government built only bidirectional spacetime tunnels between planets to ensure that any two planets are mutually reachable. For administrative reasons, the governor of the -th planet requires that each citizen must not use spacetime tunnels to leave that planet more than times within a year (this is counted by the number of departures; if you have already departed from that planet times, then you cannot leave that planet via a spacetime tunnel again within the same year).
Louis Paosen is an interstellar traveler. He hopes to use spacetime tunnels as many times as possible, but he does not want to end up settling on a planet with overly harsh conditions. Therefore, he wants to know, for each planet , if he starts from planet and finally ends his trip on planet , what is the maximum number of spacetime tunnel uses possible along the journey.
Input Format
The input file galaxy.in contains an integer on the first line.
The second line contains integers , representing the departure limit for each planet.
Each of the next lines contains two integers, indicating that there is a spacetime tunnel between these two planets.
Planets are numbered from , and Louis Paosen starts on planet .
Output Format
The output file is galaxy.out. It contains lines, each with one integer, where the integer on line is the maximum possible number of spacetime tunnel uses if the trip ends on planet .
3
2 6 2
0 1
1 2
8
7
8
Hint
For of the testdata, .
For of the testdata, .
All departure limits satisfy , and each planet’s is greater than or equal to the number of planets directly connected to it (i.e., its degree).
Translated by ChatGPT 5
京公网安备 11011102002149号