#C1915. Minimum Circular Path in Techland
Minimum Circular Path in Techland
Minimum Circular Path in Techland
You are given a map of Techland represented as an undirected weighted graph. There are n cities and m bidirectional roads. Each road connects two different cities and has an associated travel cost.
Your task is to choose four distinct cities, say i, j, k, and l (with i < j < k < l), and determine a cycle that visits these cities in the order i → j → k → l → i. The total cost of the cycle is defined as:
$D = d(i,j) + d(j,k) + d(k,l) + d(l,i)$
where $d(a,b)$ is the shortest distance between cities a and b (which can involve intermediate cities). You are required to find the set of four cities which minimizes this total cost. The answer should be output in increasing order, i.e. as a sorted list of the four city indices.
Note: It is guaranteed that there exists at least one set of four distinct cities in the input data.
inputFormat
Input Format:
- The first line contains two integers n and m -- the number of cities and the number of bidirectional roads respectively.
- Each of the next m lines contains three integers u, v, and w representing a road between cities u and v with travel cost w.
outputFormat
Output Format:
Output four space-separated integers in a single line representing the selected cities in increasing order that form the optimal cycle with minimum total travel cost.
## sample6 7
1 2 2
2 3 2
3 4 2
4 1 3
1 5 1
5 6 4
6 3 2
1 2 3 4