Algorithm · LinkedIn · Medium
You have an undirected graph with n nodes labeled from 0 to n - 1. The edges represent unit‑length roads, and multiple supply depots are placed at certain nodes. For every node, determine the minimal distance you must travel along roads to reach any depot. If a node cannot reach a depot, the distance for that node is -1. You are given: n: an integer representing the number of nodes, edges: an array of undirected connections, each as a pair [u, v] meaning a road between node…
Checking your access…