A22513.Switching on the Lights S

提高+/省选-

USACO

通过率:0%

时间限制:1.00s

内存限制:128MB

题目描述

Farm John 最近新建了一批巨大的牛棚。这些牛棚构成了一个N*N的矩形网络。(1<n<100)

然而bessie十分怕黑,他想计算可以把多少个牛棚的灯打开。
有N*N个房间,组成了一张N*N的网格图,Bessie一开始位于左上角(1,1),并且只能上下左右行走。

一开始,只有(1,1)这个房间的灯是亮着的,Bessie只能在亮着灯的房间里活动。

有另外M条信息,每条信息包含四个数a,b,c,d,表示房间(a,b)里有房间(c,d)的灯的开关。

请计算出最多有多少个房间的灯可以被打开

输入格式

第一行,两个数:N,M(1<m<200000);

第2-m+1行:坐标(x1,y1),(x2,y2)代表房间的坐标(x1,y1)及可以点亮的·房间的坐标(x2,y2);

输出格式

一个数,最多可以点亮的房间数

输入输出样例

  • 输入#1

    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
    

    输出#1

    5

说明/提示

Bessie 可以使用 (1,1)(1,1) 的开关打开 (1,2),(1,3)(1,2),(1,3) 的灯,然后走到 (1,3)(1,3) 并打开 (2,1)(2,1) 的灯,走到 (2,1)(2,1) 并打开 (2,2)(2,2) 的灯。(2,3)(2,3) 的开关无法到达。因此可以点亮 55 个房间。

Here, Bessie can use the switch in (1,1) to turn on lights in (1,2) and (1,3). She can then walk to (1,3) and turn on the lights in (2,1),from which she can turn on the lights in (2,2). The switch in (2,3) is inaccessible to her, being in an unlit room. She can therefore illuminate at most 5 rooms.

首页