#C6406. Taco Adventure: Reach the Treasure and Return

    ID: 50163 Type: Default 1000ms 256MiB

Taco Adventure: Reach the Treasure and Return

Taco Adventure: Reach the Treasure and Return

You are given an undirected graph representing rooms and corridors in a dungeon. The dungeon has n rooms and m corridors. You are also provided with two special rooms: the Entrance and the Treasure room. Your task is to determine whether it is possible to go from the Entrance to the Treasure and then return back to the Entrance.

In other words, you should check if there exists a path from the Entrance to the Treasure and a path from the Treasure back to the Entrance. Formally, let \(E\) be the Entrance and \(T\) be the Treasure. The requirement is:

[ (E \rightarrow T) \quad \text{and} \quad (T \rightarrow E) ]

If both conditions are satisfied, output YES; otherwise, output NO.

inputFormat

The input is read from stdin and is formatted as follows:

  • The first line contains two integers n and m --- the number of rooms and the number of corridors.
  • The second line contains two integers Entrance and Treasure --- the indices of the Entrance and the Treasure room.
  • The following m lines each contain two integers u and v, representing a corridor connecting room u and room v.

outputFormat

Output a single line to stdout with the string YES if it is possible to reach the Treasure room from the Entrance and then return to the Entrance, or NO otherwise.

## sample
4 4
1 4
1 2
2 3
3 4
4 1
YES