Dsa
Union Find
Easy
Optimized Task Assignment
You are organizing a team-building event involving multiple tasks and participants. The participants can team up based on their preferences. Your goal is to determine the minimum number of teams required to complete all tasks, where each team consists of participants who can work together directly or indirectly. Read the number of participants and their preferred pairwise collaborations, then output the number of distinct teams needed to ensure all tasks are covered.
Input Format:
- The first line contains an integer N (1 <= N <= 1000), the number of participants.
- Subsequent lines contain pairs of integers A and B (1 <= A, B <= N) indicating that participant A would like to work with participant B. The input ends when there are no more pairs.
Output Format:
- A single integer representing the minimum number of teams required.
Example:
Input:
6
1 2
2 3
4 5
4 6
Output:
3
Key concepts
union_findtask_assignmentoptimization
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