Build a road network by choosing one city as a hub and connecting every other city to it so that the total construction cost is small and the road set is valid.
Road Construction
You are given an undirected weighted graph with cities and possible roads. Your task is to decide which roads to build so that the cities become connected, following the problem’s construction rule.
A common formulation of this task is to pick a suitable central city and then connect other cities in a way that satisfies the required structure while keeping the construction valid. The answer is usually a list of roads to build, not a shortest-path computation.
Your goal is to output one valid construction if it exists, using the graph information provided in the input.
Input Format
- The first line contains two integers and .
- Each of the next lines describes a road between two cities.
- Depending on the exact variant, each road may also include a cost or weight.
Output Format
- Print a valid set of roads to build, or the required arrangement specified by the task.
- If multiple answers are possible, any valid one may be accepted.
Constraints
- are within standard competitive-programming limits.
- The graph description is assumed to fit in memory.
- Exact numeric limits are not available from the source metadata.
Example 1
Input
4 3 1 2 1 3 1 4
Output
1 2 1 3 1 4
Explanation
This is already a valid road construction centered at city 1.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.