HUAWEI OD machine test real questions - minimum transmission delay - 2023 OD unified test (B paper)

Title description:

There are N network nodes in a communication network, which are identified by 1 to N. The network is represented by a directed acyclic graph, where the edge values ​​of the graph represent the message delivery delays between nodes.
Now given the delay list times[i]={u,v,w} between connected nodes, where u represents the source node, v represents the destination node, and w represents the message delivery delay between u and v. Please calculate the minimum transmission delay from a given source node to a destination node, and return -1 if the destination node is unreachable.

Note:
1. The value range of N is [1,100];
2. The length of the delay list times does not exceed 6000, and 1 <= u, v <= N, 0 <= w <= 100;

Enter a description:

The first input line is two positive integers, representing the number N of network nodes and the length M of the delay list, separated by spaces; the next M line is the delay list [uvw]
between the two nodes; the
last input line is two positive integers u and v, respectively representing the source node and the destination node;

Output description:

Output an integer representing the minimum delay from the source node to the destination node.

Supplementary note:

Example 1

enter:

3 3
1 2 11
2 3 13
1 3 50
1 3

output:

24

illustrate:

The delay of 1->3 is 50, and the delay of 1->2->3 is 11+13=24, so the minimum delay from 1 to 3 is 24;



#include <iostream>
#includ

Guess you like

Origin blog.csdn.net/2301_76848549/article/details/131519867