408406: GYM103114 J Jahaxiki's journey III - Tryna lost

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Jahaxiki's journey III - Tryna losttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

As we all know, the 2020-2021 season is a boring season. Because the Fahaxiki team failed to get the spot to participate in the live game, it was tantamount to losing an opportunity to travel at public expense. But Tryna is very much looking forward to a chance to travel at public expense, he thought...

In Tryna's dream, the Fahaxiki team came to Shanghai. They visited the Oriental Pearl Tower, walked through the Bund and even went to Disneyland. However, during this trip to Disney, a little accident happened. Tryna and his teammates are separated, he can only rely on his poor sense of direction to try to find an exit and reconnect with his teammates. It is known that Tryna is a smart person. If there are some simple loads in Disney, he will try his best to walk all the roads to find the exit. At the same time Tryna is also a fool. If some roads in Disney form a ring, he will be trapped in the ring and cannot find an exit. (simple loads , here is a concept relative to ring , all roads that cannot be formed into a ring are collectively referred to as simple loads in this question)

Assuming that Disneyland is a two-dimensional plane, you don't care about the location of Tryna and the location of the exit, you only need to determine whether there is a ring in the plane that can trap Tryna. The smallest unit in the plane is a square surrounded by four sides, and each side represents the barrier from the adjacent unit. If there is no barrier between the two smallest units, it means that the two units are connected to each other. If there is no loop output YES, it means Tryna can find the exit by its own ability. Otherwise, the output NO means that poor Tryna will be trapped in Disney alone.

Input

The first line contains integers $$$n,m(1 \leq n, m, n \cdot m \leq 10^5)$$$, indicating the size of the two-dimensional plane.

Next $$$n+1$$$ lines, each line has $$$2 \cdot m+1$$$ characters. The character '|' or '_' means that there is a wall between the two points and cannot be passed through. On the contrary, a blank space means that two points are connected, representing a road.

Output

output on a separate line:

  • YES if Tryna can find an exit by its own ability
  • NO otherwise.

You can output YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

ExamplesInput
2 3
 _ _ _ 
| | |_|
|_ _|_|
Output
YES
Input
2 3
 _ _ _ 
|   |_|
|_ _|_|
Output
NO
Note

In the first example, (1,1) is connected to (2,1), (2,1) is connected to (2,2), and (2,2) is connected to (1,2). There is no ring in the plane.

In the second example, (1,1) is connected with (2,1), (2,1) is connected with (2,2), (2,2) is connected with (1,2), and (1 ,2) is connected with (1,1). A ring is formed in the plane.

加入题单

算法标签: