Dsa
Union Find
Hard
Academic Collaboration Network
In an academic institution, researchers collaborate on projects. Each researcher has a unique ID and may collaborate with multiple others. Your task is to determine how many distinct research groups exist after processing collaboration requests.
Input Format:
- The first line contains an integer n: the number of researchers (1 ≤ n ≤ 500).
- The second line contains an integer m: the number of collaboration requests (1 ≤ m ≤ 1000).
- The next m lines contain pairs of integers (a, b) showing that researchers a and b wish to collaborate.
Output Format:
- Print a single integer representing the number of distinct research groups after processing all requests.
Example:
Input:
4
3
1 2
2 3
1 4
Output:
2
Key concepts
union_findmerging_groups
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