#P11844. [USACO25FEB] Friendship Editing G
[USACO25FEB] Friendship Editing G
Description
Farmer John's cows are labeled to (). The friendship relationships between the cows can be modeled as an undirected graph with () edges. Two cows are friends if and only if there is an edge between them in the graph.
In one operation, you can add or remove a single edge from the graph. Count the minimum number of operations required to ensure that the following property holds: If cows and are friends, then for every other cow , at least one of and is friends with .
Input Format
The first line contains and .
The next lines each contain a pair of friends and (). No pair of friends appears more than once.
Output Format
The number of edges you need to add or remove.
3 1
1 2
1
3 2
1 2
2 3
0
4 4
1 2
1 3
1 4
2 3
1
Hint
For Sample 1:
The network violates the property. We can add one of edges or , or remove edge to fix this.
For Sample 2:
No changes are necessary.
SCORING:
- Inputs 4-13: One input for each in increasing order.
- Inputs 14-18:
京公网安备 11011102002149号