Breadth First Search Test

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Java 8 3.0s
Memory limit: 64M

Author:
Problem type

A basic algorithm for traversing a graph is called Breadth First Search. Use one of these algorithms on a given graph to determine if it is possible to reach one node from another.

Input Specification

The first line of input is an integer n (2 \le n \le 10^5) representing the number of nodes in this graph. They are numbered 0 to n-1.
The second line of input is an integer m (0 \le m \le 2n) representing the number of edges in this graph.
The next m lines represent an edge. They contain two space separated integers representing an edge between those nodes. These edges may not be unique.

Output Specification

If it is possible to reach node n-1 from node 0, print yes. Otherwise print no.

Sample Input

6
8
0 2
0 4
0 5
1 4
1 5
2 3
2 4
4 5

Sample Output

yes

Comments


  • 3
    EgorGor  commented on Dec. 11, 2019, 1:35 p.m.

    deep


    • -5
      Eric_Zhang  commented on Dec. 12, 2019, 8:59 a.m. edited

      This comment is hidden due to too much negative feedback. Click here to view it.