#P2845. [USACO15DEC] Switching on the Lights S
[USACO15DEC] Switching on the Lights S
Description
There are rooms forming an grid. Bessie starts at the top-left corner and can move only up, down, left, and right.
Initially, only the room is lit, and Bessie may only move through rooms whose lights are on.
There are additional pieces of information. Each describes that a switch in room controls the light in room .
Compute the maximum number of rooms whose lights can be turned on.
Input Format
The first line contains two integers (, ).
Lines to each contain four integers , meaning the switch in room can turn on the light in room .
Output Format
Output a single integer, the maximum number of rooms that can be lit.
3 6
1 1 1 2
2 1 2 2
1 1 1 3
2 3 3 1
1 3 1 2
1 3 2 1
5
Hint
Bessie can use the switch at to turn on the lights in and , then move to and turn on , move to and turn on . The switch at is unreachable. Therefore, rooms can be lit.
Translated by ChatGPT 5
京公网安备 11011102002149号