Bottleneck Travelling Salesman Problem (Small)
InterviewTime limit1sMemory limit1024 MB
Given a small directed weighted graph, find a Hamiltonian cycle minimizing the largest edge cost on the cycle, and output that cost plus one optimal tour.
- Level
Medium6 of 10
- Topics
- Graph, Brute force, Backtracking, Greedy
- Solved
- No attempts yet
Problem
The Traveling Salesman Problem (TSP) is one of the most important problems in computer science. Consider one of its variants, the Bottleneck Traveling Salesman Problem (BTSP).
You are given a directed graph with vertices and weighted edges. Starting at some vertex, you want to find a tour that visits each of the other vertices exactly once and returns to the starting vertex. There can be several such tours, and you want to minimize the maximum edge cost along the tour.
Given a graph, find a tour that visits every vertex while minimizing the maximum edge cost.
Input
The first line contains the number of vertices and the number of edges . (, )
The next lines each contain three integers , , describing an edge. This means there is an edge from vertex to vertex with cost . No two edges in the same direction connect the same pair of vertices. (, , )
Output
If a tour visiting every vertex exists, print the minimum possible maximum edge cost on the first line. If no such tour exists, print -1.
If a tour visiting every vertex exists, print on the next line the vertex numbers in the order they are visited, chosen so that the maximum edge cost is minimized. If several such tours exist, you may print any of them.