#C9453. Haunted Mansion: The Shortest Path
Haunted Mansion: The Shortest Path
Haunted Mansion: The Shortest Path
You are trapped in a haunted mansion consisting of n rooms connected by m corridors. Each corridor connects two rooms and has two attributes: its length d and an accessibility flag a (where a = 1
means the corridor is accessible and a = 0
means it is blocked).
Your task is to determine the shortest path from room 1 to room n using only accessible corridors. If there exists no path from room 1 to room n through accessible corridors, output IMPOSSIBLE
.
Note: Use \(\LaTeX\) format for all formulas. For example, the distance from room 1 to room n is given by \(d(1, n)\), which should be minimized.
inputFormat
The first line contains two integers n
and m
, where n
is the number of rooms and m
is the number of corridors.
Each of the following m
lines contains four integers: u
, v
, d
, and a
. Here, u
and v
denote the rooms connected by the corridor, d
represents the length of the corridor, and a
is the accessibility flag (1 if accessible, 0 if blocked).
outputFormat
Output a single line with the minimum distance from room 1 to room n
if a valid path exists. Otherwise, output IMPOSSIBLE
.
5 6
1 2 2 1
2 3 1 1
3 5 5 0
1 4 1 1
4 5 3 1
2 5 5 1
4