A990.Minimizing Edges--Platinum

NOI/NOI+/CTSC

USACO

通过率:0%

时间限制:1.00s

内存限制:128MB

题目描述

Bessie has a connected, undirected graph GG with NN vertices labeled
1…N1\ldots N and MM edges (2≤N≤105,N−1≤M≤N2+N22\le N\le 10^5, N-1\le M\le \frac{N^2+N}{2}). GG
may contain self-loops (edges from nodes back to themselves), but no parallel
edges (multiple edges connecting the same endpoints).
Let fG(a,b)f_G(a,b) be a boolean function that evaluates to true if there exists a
path from vertex 11 to vertex aa that traverses exactly bb edges for each
1≤a≤N1\le a\le N and 0≤b0\le b, and false otherwise. If an edge is traversed
multiple times, it is included that many times in the count.
Elsie wants to copy Bessie. In particular, she wants to construct an
undirected graph G′G' such that fG′(a,b)=fG(a,b)f_{G'}(a,b)=f_G(a,b) for all aa and bb.
Elsie wants to do the least possible amount of work, so she wants to construct
the smallest possible graph. Therefore, your job is to compute the minimum
possible number of edges in G′G'.
Each input contains TT (1≤T≤5⋅1041\le T\le 5\cdot 10^4) test cases that should be
solved independently. It is guaranteed that the sum of NN over all test cases
does not exceed 10510^5, and the sum of MM over all test cases does not exceed
2⋅1052\cdot 10^5.

输入格式

The first line of the input contains TT, the number of test cases.
The first line of each test case contains two integers NN and MM.
The next MM lines of each test case each contain two integers xx and yy
(1≤x≤y≤N1\le x\le y\le N), denoting that there exists an edge between xx and yy
in GG.
Consecutive test cases are separated by newlines for readability.

输出格式

For each test case, the minimum possible number of edges in G′G' on a new
line.

输入输出样例

  • 输入#1

    2
    5 5
    1 2
    2 3
    2 5
    1 4
    4 5
    5 5
    1 2
    2 3
    3 4
    4 5
    1 5
    

    输出#1

    4
    5
    

说明/提示

In the first test case, Elsie can construct G′G' by starting with GG and
removing (2,5)(2,5). Or she could construct a graph with the following edges,
since she isn't restricted to just removing edges from GG:
1 2
1 4
4 3
4 5
Elsie definitely cannot do better than N−1N-1 since G′G' must also be
connected.

输入解题思路,AI测评打分。不知道怎么写?

首页