Question bank › Union Find
Dsa Union Find Medium

City Connection Planning

You are involved in a project that requires planning the connection of various cities. Given a list of potential connection plans between cities and their costs, your task is to determine the minimum cost to connect all cities. Each connection can either be built or ignored based on cost-effectiveness. Your program should utilize the union-find data structure to solve this problem. Input Format: - The first line contains an integer C, the number of connection proposals (1 <= C <= 10000). - Each of the next C lines contains three integers: - City_A (1 <= City_A <= 1000) - City_B (1 <= City_B <= 1000) - Cost (1 <= Cost <= 10000) Output Format: - Print the total minimum cost to connect all cities using the given proposals. Example: Input: 4 1 2 4 1 3 1 2 3 2 3 4 3 Output: 6 Note: - The connection is based on minimizing cost while ensuring all cities are connected.

Key concepts

union_findcitiesinfrastructure

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.