#K76682. Green Light Path

    ID: 34697 Type: Default 1000ms 256MiB

Green Light Path

Green Light Path

You are given an n x m grid representing a network of traffic lights. Each cell in the grid is marked with either a 'G' (green) or an 'R' (red). Your task is to determine whether there exists a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell (n,m)) such that you only pass through cells with green lights ('G'). Movement is allowed in four directions: up, down, left, and right. If such a path exists, output YES; otherwise, output NO.

inputFormat

The input is read from stdin. The first line contains two integers n and m, indicating the number of rows and columns. The following n lines each contain a string of exactly m characters. Each character is either 'G' (green) or 'R' (red), representing the state of the traffic light at that position.

outputFormat

Output a single line to stdout: YES if there exists a path from the top-left to the bottom-right that passes only through cells with a 'G', otherwise output NO.## sample

5 5
GGGGG
RGRGR
GRRGG
RGRGR
GGGGG
YES