CF1680F.Lenient Vertex Cover

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a simple connected undirected graph, consisting of nn vertices and mm edges. The vertices are numbered from 11 to nn.

A vertex cover of a graph is a set of vertices such that each edge has at least one of its endpoints in the set.

Let's call a lenient vertex cover such a vertex cover that at most one edge in it has both endpoints in the set.

Find a lenient vertex cover of a graph or report that there is none. If there are multiple answers, then print any of them.

给你一个简单连通无向图,包含 nn 个顶点和 mm 条边。顶点编号为 11 到 nn。

图的一个顶点覆盖(vertex cover)是指一个顶点集合,使得图中的每条边至少有一个端点属于该集合。

我们称一个宽松顶点覆盖(lenient vertex cover)为一种顶点覆盖,其中至多有一条边的两个端点均在该集合中。

请找出该图的一个宽松顶点覆盖;若不存在,则报告无解。若存在多个解,输出任意一个即可。

输入格式

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

The first line of each testcase contains two integers nn and mm (2≤n≤1062 \le n \le 10^6; n−1≤m≤min⁡(106,n⋅(n−1)2)n - 1 \le m \le \min(10^6, \frac{n \cdot (n - 1)}{2})) — the number of vertices and the number of edges of the graph.

Each of the next mm lines contains two integers vv and uu (1≤v,u≤n1 \le v, u \le n; v≠uv \neq u) — the descriptions of the edges.

For each testcase, the graph is connected and doesn't have multiple edges. The sum of nn over all testcases doesn't exceed 10610^6. The sum of mm over all testcases doesn't exceed 10610^6.

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

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤1062 \le n \le 10^6;n−1≤m≤min⁡(106,n⋅(n−1)2)n - 1 \le m \le \min(10^6, \frac{n \cdot (n - 1)}{2}))—— 图的顶点数和边数。

接下来的 mm 行中,每行包含两个整数 vv 和 uu(1≤v,u≤n1 \le v, u \le n;v≠uv \neq u)—— 描述一条边。

对于每个测试用例,图是连通的,且不含重边。所有测试用例的 nn 之和不超过 10610^6。所有测试用例的 mm 之和不超过 10610^6。

输出格式

For each testcase, the first line should contain YES if a lenient vertex cover exists, and NO otherwise. If it exists, the second line should contain a binary string ss of length nn, where si=1s_i = 1 means that vertex ii is in the vertex cover, and si=0s_i = 0 means that vertex ii isn't.

If there are multiple answers, then print any of them.

对于每个测试用例,第一行应输出 YES(如果存在一个宽松顶点覆盖),否则输出 NO。如果存在这样的覆盖,第二行应输出一个长度为 nn 的二进制字符串 ss,其中 si=1s_i = 1 表示顶点 ii 属于该顶点覆盖,而 si=0s_i = 0 表示顶点 ii 不属于该顶点覆盖。

如果存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    6 5
    1 3
    2 4
    3 4
    3 5
    4 6
    4 6
    1 2
    2 3
    3 4
    1 4
    1 3
    2 4
    8 11
    1 3
    2 4
    3 5
    4 6
    5 7
    6 8
    1 2
    3 4
    5 6
    7 8
    7 2
    4 5
    1 2
    2 3
    3 4
    1 3
    2 4

    输出#1

    YES
    001100
    NO
    YES
    01100110
    YES
    0110
  • 输入#2

    1
    10 15
    9 4
    3 4
    6 4
    1 2
    8 2
    8 3
    7 2
    9 5
    7 8
    5 10
    1 4
    2 10
    5 3
    5 7
    2 9

    输出#2

    YES
    0101100100
  • 输入#3

    1
    10 19
    7 9
    5 3
    3 4
    1 6
    9 4
    1 4
    10 5
    7 1
    9 2
    8 3
    7 3
    10 9
    2 10
    9 8
    3 2
    1 5
    10 7
    9 5
    1 2

    输出#3

    YES
    1010000011

说明/提示

Here are the graphs from the first example. The vertices in the lenient vertex covers are marked red.

以下是第一个示例中的图。宽限顶点覆盖(lenient vertex cover)中的顶点标为红色。

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

首页