GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.hackerrank.com — BFS: Shortest Reach in a Graph | HackerRank 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. Consider an undirected graph consisting of nodes where each node is labeled from to and the edge between any two nodes is always of length . We define node to be the starting position for a BFS. Given a graph, determine the distances from the start node to each of its descendants and return the list in node number order, ascending. If a node is disconnected, it's distance should be . For example, there are nodes in the graph with a starting node . The list of , and each has a weight of .
Starting from node and creating a list of distances, for nodes through we have . Function Description Define a Graph class with the required methods to return a list of distances. Input Format The first line contains an integer, , the number of queries. Each of the following sets of lines is as follows:
Constraints Output Format For each of the queries, print a single line of space-separated integers denoting the shortest distances to each of the other nodes from starting position . These distances should be listed sequentially by node number (i.e., ), but should not include node . If some node is unreachable from , print as the distance to that node. Sample Input Sample Output Explanation We perform the following two queries:
Note: Recall that the actual length of each edge is , and we print as the distance to any node that's unreachable from . Cookie support is required to access HackerRankSeems like cookies are disabled on this browser, please enable them to open this website |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |