Dsa
Union Find
Easy
Project Collaborations
In a company, employees can form teams to work on projects if they have previously collaborated on at least one project. Given a list of pairings representing collaboration between employees on projects, determine how many distinct teams can be formed.
Input:
- The first line contains an integer n (1 <= n <= 100), the number of employees.
- The second line contains an integer m (0 <= m <= n*(n-1)/2), the number of collaboration pairs.
- Each of the following m lines contains two integers a and b, which denote that employee a collaborated with employee b.
Output:
- Print the number of distinct teams that can be formed.
Example:
Input:
4
3
0 1
1 2
3 3
Output:
2
Key concepts
union_findteamsprojects
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