#C10667. Assign Weights to Maintain Shortest Paths

    ID: 39897 Type: Default 1000ms 256MiB

Assign Weights to Maintain Shortest Paths

Assign Weights to Maintain Shortest Paths

You are given a list of edges in a graph. Each edge is represented by three integers u, v, and l, which denote an edge connecting node u and node v with an initial length l. Your task is to assign positive weights to these edges such that the sum of all weights is minimized while maintaining the same shortest path distances between all nodes.

It turns out that to preserve the shortest paths, each edge must retain its original weight. In other words, the only valid assignment is to keep w = l for every edge. This is a straightforward but fundamental problem in understanding how edge weights affect shortest path computations.

The problem may also be represented mathematically with the following idea:

$$\min \sum_{e \in E} w_e \quad \text{subject to} \quad w_e = l_e \text{ for each edge } e \in E, $$

where \(E\) is the set of edges, \(l_e\) is the initial length of edge \(e\), and \(w_e\) is the weight to be assigned.

inputFormat

The input is read from stdin and has the following format:

m
u1 v1 l1
nu2 v2 l2
... 
num vnum lnum

Here, the first line contains a single integer m representing the number of edges. Each of the next m lines contains three space-separated integers: u, v, and l, representing an edge from node u to node v with an initial length l.

outputFormat

Output to stdout m lines, where each line contains three integers in the exact same order as the input. Each line should be in the format:

u v w

Note that w is equal to the original length l of the edge, ensuring the shortest path distances remain unchanged.

## sample
6
1 2 3
1 3 5
2 3 4
3 4 1
3 5 2
4 5 7
1 2 3

1 3 5 2 3 4 3 4 1 3 5 2 4 5 7

</p>