CommvaultOA #3
Number of Good Pairs
估计中等可在线判题
考点(AI 标注)并查集
In an undirected graph, count the unordered node pairs whose endpoints belong to different connected components.
This site's standard input/output format and supplementary bounds follow this problem's description.
输入格式
The input is N M (1≤N≤65,535, 0≤M≤2×10^5), followed by M lines of edges u v (1-based, 1≤u,v≤N). Duplicate edges and self-loops are allowed, and the result fits safely in a signed 32-bit integer.
输出格式
Output the good pair count (as a 64-bit integer).
样例 1
输入:
5 3
1 2
2 3
4 5
输出:
6
样例 2
输入:
4 0
输出:
6
样例 3
输入:
1 2
1 1
1 1
输出:
0