Question: Use C or C++. Time Limit : 1 sec Mike is a road builder. Mike has many girlfriends. They all live in different cities, Mike
Use C or C++.
Time Limit : 1 sec
Mike is a road builder.
Mike has many girlfriends. They all live in different cities,
Mike wants to visit all his girlfriends by a single road.
Mike found that the cost of building a highway varies from city to city.
The good news is that two cities that are not directly connected by road can be connected by passing through other cities (maybe most) connected.
He hopes to travel between all cities, but build the road at the lowest cost.
can you help him?
Please output:
No, if you don't want to help him or
{Cost} If you are willing to help him, export all cities directly or indirectly connected, and spend the cheapest price (Do not output Yes)
Input description:
This question is a single input and output, and the program can be ended after the output is completed.
First, there will be two integers V, E separated by a space, which means that there are V girlfriends in total. There is a way to build E roads (not all of them), and then there will be E lines.
For each road E_i, there are three integers V_a, V_b, W_i separated by spaces, representing the cost of connecting V_a, V_b is W_i
(V_a, V_b are two-way roads with different starting and ending points - no self-loop)

Guarantee that all cities can be directly or indirectly connected by road.
Output description: In total, only one line needs to be output, that is, the minimum cost of No or equal weft. Please wrap the line at the end of the line.
Do not output other extraneous text (e.g Please enter:, Your Answer:, End!!)

Tips:
- You can complete Task 2 first and then optimize the code to complete Task 3
- Kruskal can refer to Disjoin set
- Prim can refer to Fibonacci heap
- Don't use system("pause") or redundant header files like conio.h
- 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
