Problem statement
Write function solution(nodes, edges, start). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. nodes is an array of distinct strings and includes start. edges is an array of directed {from:string,to:string,cost:nonnegative integer} edges. Ignore edges containing unknown nodes. Find the minimum cost from start to every node and return {id,distance} objects in nodes input order. The distance to start is 0; unreachable nodes use null. Zero costs, duplicate edges, and self-loops are valid. All path-cost sums are safe integers. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
"a",
"b",
"c"
],
[
{
"from": "a",
"to": "b",
"cost": 2
},
{
"from": "b",
"to": "c",
"cost": 3
}
],
"a"
]Return value
[
{
"id": "a",
"distance": 0
},
{
"id": "b",
"distance": 2
},
{
"id": "c",
"distance": 5
}
]Example 2
Function arguments
[
[
"a",
"b"
],
[],
"a"
]Return value
[
{
"id": "a",
"distance": 0
},
{
"id": "b",
"distance": null
}
]Example 3
Function arguments
[
[
"a",
"b"
],
[
{
"from": "x",
"to": "b",
"cost": 1
},
{
"from": "a",
"to": "x",
"cost": 1
}
],
"a"
]Return value
[
{
"id": "a",
"distance": 0
},
{
"id": "b",
"distance": null
}
]