CF1903F.Babysitting

省选/NOI-

通过率:0%

时间限制:7.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Theofanis wants to play video games, however he should also take care of his sister. Since Theofanis is a CS major, he found a way to do both. He will install some cameras in his house in order to make sure his sister is okay.

His house is an undirected graph with nn nodes and mm edges. His sister likes to play at the edges of the graph, so he has to install a camera to at least one endpoint of every edge of the graph. Theofanis wants to find a vertex cover that maximizes the minimum difference between indices of the chosen nodes.

More formally, let a1,a2,…,aka_1, a_2, \ldots, a_k be a vertex cover of the graph. Let the minimum difference between indices of the chosen nodes be the minimum ∣ai−aj∣\lvert a_i - a_j \rvert (where i≠ji \neq j) out of the nodes that you chose. If k=1k = 1 then we assume that the minimum difference between indices of the chosen nodes is nn.

Can you find the maximum possible minimum difference between indices of the chosen nodes over all vertex covers?

西奥法尼斯想玩电子游戏,但他同时也需要照看他的妹妹。由于西奥法尼斯是计算机科学专业的学生,他找到了一种兼顾二者的方法:他将在家中安装若干摄像头,以确保妹妹的安全。

他的家是一个具有 nn 个节点和 mm 条边的无向图。他的妹妹喜欢在图的边上玩耍,因此他必须在图的每条边的至少一个端点处安装摄像头。西奥法尼斯希望找到一个顶点覆盖,使得所选节点下标之间的最小差值尽可能大。

更准确地说,设 a1,a2,…,aka_1, a_2, \ldots, a_k 是该图的一个顶点覆盖。所选节点下标之间的最小差值定义为所有所选节点中 ∣ai−aj∣\lvert a_i - a_j \rvert(其中 i≠ji \neq j)的最小值。若 k=1k = 1(即仅选一个节点),则约定该最小差值为 nn。

你能否找出在所有顶点覆盖中,所选节点下标之间可能达到的最大最小差值?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn and mm (1≤n≤105,1≤m≤2⋅1051 \le n \le 10^{5}, 1 \le m \le 2 \cdot 10^{5}) — the number of nodes and the number of edges.

The ii-th of the following mm lines in the test case contains two positive integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i,v_i \le n), meaning that there exists an edge between them in the graph.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^{5}.

It is guaranteed that the sum of mm over all test cases does not exceed 2⋅1052 \cdot 10^{5}.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤105, 1≤m≤2⋅1051 \le n \le 10^{5},\ 1 \le m \le 2 \cdot 10^{5})—— 分别表示节点数和边数。

在每个测试用例接下来的 mm 行中,第 ii 行包含两个正整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \le u_i,v_i \le n),表示图中存在一条连接 uiu_i 和 viv_i 的边。

保证所有测试用例的 nn 之和不超过 10510^{5}。

保证所有测试用例的 mm 之和不超过 2⋅1052 \cdot 10^{5}。

输出格式

For each test case, print the maximum minimum difference between indices of the chosen nodes over all vertex covers.

对于每个测试用例,输出所有顶点覆盖中所选节点下标之间最小差值的最大值。

输入输出样例

  • 输入#1

    3
    7 6
    1 2
    1 3
    1 4
    1 6
    2 3
    5 7
    3 3
    1 2
    1 3
    1 1
    2 4
    1 2
    1 2
    2 1
    1 1

    输出#1

    2
    3
    2

说明/提示

In the first test case, we can install cameras at nodes 11, 33, and 77, so the answer is 22.

In the second test case, we can install only one camera at node 11, so the answer is 33.

在第一个测试用例中,我们可以在节点 11、33 和 77 处安装摄像头,因此答案为 22。

在第二个测试用例中,我们只能在节点 11 处安装一个摄像头,因此答案为 33。

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

首页