We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Graph Theory
- Rust & Murderer
- Discussions
Rust & Murderer
Rust & Murderer
Sort by
recency
|
68 Discussions
|
Please Login in order to post a comment
Java solution below. BFS can be used for single source shortest distances in unweighted graphs, which is what this is. Build an adjacency list for city roads (since this graph is sparse, we'd want to be looking for nonexistence of city roads rather than existance of village roads during BFS, for efficiency). Keep track of unvisited nodes with a set.
For Solving this question here is my submission: 1- Find the adjacency list of compliment of the graph (this will be representing the village roads) 2- Run he BFS with shortest distance
This is the simplest method in which this problem can be solved
Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Rust & Murderer Problem Solution
Here is the solution of Rust & Murderer Click here