#C5762. Network File Transfer
Network File Transfer
Network File Transfer
Given a network of (n) computers and (m) directional connections, determine if there exists a path from the source computer (s) to the destination computer (d). Each connection is represented by a pair of integers ((u,v)) which indicates a directed edge from computer (u) to computer (v).
If (s = d), the file transfer is trivial. Otherwise, you should use a graph traversal algorithm such as breadth-first search (BFS) or depth-first search (DFS) to decide if a valid path exists.
It is guaranteed that (1 \leq n \leq 10^5) and (0 \leq m \leq 10^5) in typical test cases.
inputFormat
The input is read from standard input (stdin) with the following format:
(n) and (m): The first line contains two integers representing the number of computers and the number of connections, respectively.
Next (m) lines: Each of the following (m) lines contains two integers (u) and (v) indicating a directed connection from computer (u) to computer (v).
Last line: Contains two integers (s) and (d), the source and destination computers, respectively.
outputFormat
Output a single line containing the word "YES" if there exists a path from (s) to (d). Otherwise, output "NO".## sample
4 4
1 2
2 3
3 4
4 2
1 4
YES