Answer to Question #309406 in Algorithms for Akash srivastava

Question #309406

Has Path

Time Limit: 2 sec

Memory Limit: 128000 kB

Problem Statement

Given an undirected graph G (V, E) and two vertices v1 and v2 (as integers), check if there exists any path between them or not. Print true or false.

V is the number of vertices present in graph G and vertices are numbered from 0 to V-1.

E is the number of edges present in graph G.

Input

Line 1: Two Integers V and E (separated by space)

Next E lines: Two integers a and b, denoting that there exists an edge between vertex a and vertex b (separated by space)

Line (E+2): Two integers v1 and v2 (separated by space)


Constraints :

2 <= V <= 1000

1 <= E <= 1000

0 <= v1, v2 <= V-1

Output

For each testcase in new line, you need to print true or false.

Example

Sample Input 1 :

4 4

0 1

0 3

1 2

2 3

1 3


Sample Output 1 :

true


Explanation:

There are multiple path exists between 1 and 3. One of them is as such: 1 -> 2 -> 3.



0
Service report
It's been a while since this question is posted here. Still, the answer hasn't been got. Consider converting this question to a fully qualified assignment, and we will try to assist. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS