CT056

Auntie Loop’s Friend Network

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Auntie Loop is organizing a neighborhood potluck. Friendships connect homes; count the number of separate invitation circles. Input: n m and m undirected friendship pairs (1-based). Output: number of connected groups.

Example 1:

Input: 5 3 1 2 2 3 4 5
Output: 2

Example 2:

Input: 4 0
Output: 4

Example 3:

Input: 3 3 1 2 2 3 1 3
Output: 1

Constraints:

1≤n≤200000; 0≤m≤300000.

Tags:

dsu graphs
Loading...
Test Cases:No test cases
No test cases available.