CF1144F.Graph Without Long Directed Paths

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self-loops or multiple edges in the given graph.

You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).

给你一个由 nn 个顶点和 mm 条边组成的连通无向图。给定图中不存在自环或重边。

你需要将它的边定向,使得所得的有向图不包含长度为二或更大的路径(路径长度定义为所经过的边的数量)。

输入格式

The first line contains two integer numbers nn and mm (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, n−1≤m≤2⋅105n - 1 \le m \le 2 \cdot 10^5) — the number of vertices and edges, respectively.

The following mm lines contain edges: edge ii is given as a pair of vertices uiu_i, viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i). There are no multiple edges in the given graph, i. e. for each pair (ui,viu_i, v_i) there are no other pairs (ui,viu_i, v_i) and (vi,uiv_i, u_i) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).

第一行包含两个整数 nn 和 mm(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,n−1≤m≤2⋅105n - 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,ui≠viu_i \ne v_i)给出。给定图中不存在重边,即对任意一对 (ui,vi)(u_i, v_i),列表中不包含其他形如 (ui,vi)(u_i, v_i) 或 (vi,ui)(v_i, u_i) 的边。此外,保证给定图是连通的(图中任意两个顶点之间均存在路径)。

输出格式

If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line.

Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length mm. The ii-th element of this string should be '0' if the ii-th edge of the graph should be directed from uiu_i to viv_i, and '1' otherwise. Edges are numbered in the order they are given in the input.

如果无法将给定图的边定向,使得所得有向图不包含长度至少为 2 的路径,则在第一行输出 "NO"。

否则,在第一行输出 "YES",然后输出任意一种满足条件的边定向方案:一个长度为 mm 的二进制字符串(仅由字符 '0' 和 '1' 组成)。该字符串的第 ii 个字符应为 '0',表示图中第 ii 条边应从 uiu_i 指向 viv_i;否则(即从 viv_i 指向 uiu_i)应为 '1'。边的编号顺序与其在输入中出现的顺序一致。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    10100

说明/提示

The picture corresponding to the first example:

And one of possible answers:

第一个示例对应的图片:

其中一个可能的答案:

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

首页