← 返回 google 的题目列表Graph Problem with Weighted Edge Follow-up
类型:online_judge
Given an undirected graph, design an algorithm to compute the shortest path from a specific node to all other nodes. The edges between nodes can have different weights. Provide an input string representing the graph structure in the following format: node1 node2 weight; node1 node3 weight; .... The input ends with -1. For example, input 1 2 5; 1 3 10; 2 3 1; -1. Output the shortest path distances from the start node to each other node. Assume the graph is connected.
Example
Input
1 2 5; 1 3 10; 2 3 1; 1