Sinchon Defense HQ Escape
Time limit1sMemory limit1024 MB
Route people from building 1 to exit building N through corridors that catch fire and collapse, maximizing evacuees first, then escape time, then fatigue.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, BFS
- Solved
- No attempts yet
Problem

On August 21, 2021, the Sinchon Defense Headquarters was attacked by an unknown organization. The headquarters repelled the attack with a strong response, but the organization did not forget and waited for a chance to strike again. On February 25, 2023, after two years of waiting, the organization hit the headquarters building directly, and a fire broke out inside it. As the commander of the Sinchon Defense Headquarters, you want to evacuate as many people as possible from the fire.
The headquarters is a connected graph of buildings and two-way corridors that link them. The buildings are numbered from to . Several corridors may connect the same pair of buildings. The fire starts in building , and the exit is in building . Leaving through building takes so little time that it can be treated as . One hour after a building catches fire, it passes the fire to every connected building that has not yet caught fire through a corridor. A building collapses completely hours after it catches fire, and no one can pass through it. People cannot enter a corridor connected to a building, or the exit, even at exactly hours after the fire starts.
Initially, building has people. People move through corridors. Each corridor has a capacity , which is the maximum number of people that can enter it in one hour, a travel time , and a fatigue value , which increases by for each person entering it.
Your goal is to evacuate the largest possible number of people in the shortest possible escape time with the smallest total fatigue. These goals are ranked in that order: number of people, then escape time, then fatigue. The escape time is the time when the last person escapes, and it is if no one escapes.
Input
The first line contains the number of buildings , the number of corridors , and the time it takes for a building to collapse completely, separated by spaces. ()
The second line contains the number of people in building , separated by spaces. ()
From the third line, lines follow. The -th line contains , separated by spaces.
This means that the corridor connecting building and building has the values , , and described above. ()
All given numbers are integers.
Output
Print the maximum number of people that can be evacuated, the shortest escape time for evacuating that maximum number of people, and the minimum total fatigue when evacuating the maximum number of people in the shortest escape time, separated by spaces on one line.