#P6680. [CCO 2019] Marshmallow Molecules
[CCO 2019] Marshmallow Molecules
Description
There is an undirected graph with vertices and edges. The graph has no multiple edges and no self-loops.
If and there is an edge between and , and there is also an edge between and , then an edge will be added between and .
Find the final number of edges.
Input Format
The first line contains two integers and .
The next lines each contain two integers and , indicating that there is an edge connecting and .
Output Format
Only one line with one integer, representing the final number of edges.
6 4
1 2
1 4
4 6
4 5
6
7 6
2 3
2 6
2 7
1 3
1 4
1 5
16
Hint
Explanation for Sample 1
You need to add two edges, and .
Constraints and Limits
For of the testdata, it is guaranteed that , .
| Subtask | Special Constraints | Score | |
|---|---|---|---|
| 1 | None | ||
| 2 | |||
| 3 | No special limit | For every , there is at least one pair with | |
| 4 | None |
Notes
This problem is translated from Canadian Computing Olympiad 2019 Day 2 T2 Marshmallow Molecules。
Translated by ChatGPT 5
京公网安备 11011102002149号