CF2260F.Edge Three-Coloring

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an undirected connected graph with nn vertices and mm edges, where m≤n+9m \le n + 9.

Each edge of the graph must be colored with one of three colors numbered from 11 to 33. We say that vertices uu and vv are reachable in color cc if there exists a path from uu to vv consisting only of edges of color cc.

Determine whether there exists a way to color the edges such that the following conditions are satisfied:

  • for each color, there is at least one edge painted in that color;
  • for every pair of colors ii and jj and every pair of vertices uu and vv, the following holds: if uu and vv are reachable in color ii and i<ji \lt j, then they are also reachable in color jj.

给你一个包含 nn 个顶点和 mm 条边的无向连通图,其中 m≤n+9m \le n + 9。

图中的每条边必须被染成三种颜色之一(颜色编号为 11 至 33)。我们称顶点 uu 和 vv 在颜色 cc 下可达,当且仅当存在一条仅由颜色 cc 的边构成的从 uu 到 vv 的路径。

请判断是否存在一种边染色方案,使得以下条件均满足:

  • 每种颜色至少有一条边被染成该颜色;
  • 对任意两种颜色 ii 和 jj(其中 i<ji < j)以及任意两个顶点 uu 和 vv,若 uu 和 vv 在颜色 ii 下可达,则它们在颜色 jj 下也必须可达。

输入格式

The first line contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

Each test case begins with a line that contains two integers nn and mm (2≤n≤30002 \le n \le 3000; n−1≤m≤n+9n - 1 \le m \le n + 9) — the number of vertices and edges in the graph.

Each of the next mm lines of a test case contains two integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i) — the endpoints of the ii-th edge.

Additional constraints on the input:

  • the sum of nn over all test cases does not exceed 30003000;
  • in each test case, the graph has no self-loops or multiple edges;
  • in each test case, the graph is connected.

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

每个测试用例以一行开始,该行包含两个整数 nn 和 mm(2≤n≤30002 \le n \le 3000;n−1≤m≤n+9n - 1 \le m \le n + 9)—— 图中顶点和边的数量。

接下来的 mm 行,每行包含两个整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \le u_i, v_i \le n,ui≠viu_i \ne v_i)—— 第 ii 条边的两个端点。

输入的额外约束条件:

  • 所有测试用例的 nn 之和不超过 30003000;
  • 每个测试用例中,图不含自环或重边;
  • 每个测试用例中,图是连通的。

输出格式

For each test case, print the answer as follows: if such an edge coloring exists, print YES; otherwise, print NO. Each letter may be printed in any case.

对于每个测试用例,按如下方式输出答案:如果存在满足条件的边染色方案,则输出 YES;否则输出 NO。每个字母可使用任意大小写形式。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    NO
    NO
    YES

说明/提示

In the first example, it's possible to paint the 55-th edge in color 11, the 11-st and the 44-th edge in color 22, and all other edges in color 33.

在第一个例子中,可以将第 55 条边涂成颜色 11,第 11 条和第 44 条边涂成颜色 22,其余所有边涂成颜色 33。

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

首页