luogu#P2845. [USACO15DEC] Switching on the Lights S
[USACO15DEC] Switching on the Lights S
Background
Source: usaco-2015-dec.
Farmer John recently built a large set of barns arranged in an rectangular grid ().
However, Bessie is afraid of the dark and wants to know how many barns’ lights she can turn on.
Problem 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