| 2026 Spring UT CS104c Final Exam |
|---|
| Finished |
You are the Lead Engineer for the province of Spongeland, which consists of $$$n$$$ cities. Your mission is to establish a highway network such that every city is reachable from every other city through a series of connected roads.
There are $$$m$$$ potential highway proposals available for construction. Each proposal $$$i$$$ (where $$$1 \le i \le m$$$) is defined by:
However, the provincial government has already signed a non-negotiable contract for proposal $$$j$$$. This specific highway must be included in your final network, regardless of its cost or how it affects the overall efficiency.
Calculate the minimum total cost to connect all $$$n$$$ cities, ensuring that proposal $$$j$$$ is part of the infrastructure.
The first line contains two integers: $$$n$$$ (number of cities) and $$$m$$$ (number of proposals). The second line contains an integer $$$j$$$, representing the index of the mandatory proposal. The following $$$m$$$ lines each contain three integers $$$u_i, v_i$$$, and $$$c_i$$$, representing the $$$i$$$-th proposal.
A single integer representing the minimum cost to connect all $$$n$$$ cities including proposal $$$j$$$. Note: Use a 64-bit integer type to avoid overflow.
4 531 2 102 3 53 4 501 4 202 4 15
65
The mandatory proposal is proposal $$$3$$$, which connects cities $$$3$$$ and $$$4$$$ with cost $$$50$$$.
After including this proposal, one optimal way to finish connecting all cities is to also include: $$$$$$ (2, 3) \text{ with cost } 5 $$$$$$ and $$$$$$ (1, 2) \text{ with cost } 10. $$$$$$
These three highways connect all $$$4$$$ cities: $$$$$$ 1 \leftrightarrow 2 \leftrightarrow 3 \leftrightarrow 4. $$$$$$
The total cost is $$$$$$ 50 + 5 + 10 = 65. $$$$$$
Therefore, the minimum total cost including proposal $$$3$$$ is $$$65$$$.
| Name |
|---|


