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.
Start out by making an adjacency list from the cities array, any cities not in the array will be considered a 'component'. A component is a group of connected nodes in an undirected graph. Find the number of components using DFS. The number of roads will be equal to the number of cities - number of components. Every component will need one library.
Roads and Libraries
You are viewing a single comment's thread. Return to all comments →
Start out by making an adjacency list from the cities array, any cities not in the array will be considered a 'component'. A component is a group of connected nodes in an undirected graph. Find the number of components using DFS. The number of roads will be equal to the number of cities - number of components. Every component will need one library.