Loading...
Loading...
Loading...
Some offices are joined by two-way links. Decide whether a message can travel from office s to office t using any number of links.
Example 1
Input
5 3 0 1 1 2 3 4 0 2
Output
YES
Offices 0, 1, 2 are linked in a chain.
Example 2
Input
5 3 0 1 1 2 3 4 0 4
Output
NO
Try the problem first. Open one hint at a time.
Run a search from s and remember every node you reach.
If t is among them, the answer is YES.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor