CF1144F.Graph Without Long Directed Paths
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a connected undirected graph consisting of n vertices and m 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).
给你一个由 n 个顶点和 m 条边组成的连通无向图。给定图中不存在自环或重边。
你需要将它的边定向,使得所得的有向图不包含长度为二或更大的路径(路径长度定义为所经过的边的数量)。
输入格式
The first line contains two integer numbers n and m (2≤n≤2⋅105, n−1≤m≤2⋅105) — the number of vertices and edges, respectively.
The following m lines contain edges: edge i is given as a pair of vertices ui, vi (1≤ui,vi≤n, ui=vi). There are no multiple edges in the given graph, i. e. for each pair (ui,vi) there are no other pairs (ui,vi) and (vi,ui) 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).
第一行包含两个整数 n 和 m(2≤n≤2⋅105,n−1≤m≤2⋅105),分别表示顶点数和边数。
接下来的 m 行描述各条边:第 i 条边由一对顶点 ui、vi(1≤ui,vi≤n,ui=vi)给出。给定图中不存在重边,即对任意一对 (ui,vi),列表中不包含其他形如 (ui,vi) 或 (vi,ui) 的边。此外,保证给定图是连通的(图中任意两个顶点之间均存在路径)。
输出格式
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 m. The i-th element of this string should be '0' if the i-th edge of the graph should be directed from ui to vi, and '1' otherwise. Edges are numbered in the order they are given in the input.
如果无法将给定图的边定向,使得所得有向图不包含长度至少为 2 的路径,则在第一行输出 "NO"。
否则,在第一行输出 "YES",然后输出任意一种满足条件的边定向方案:一个长度为 m 的二进制字符串(仅由字符 '0' 和 '1' 组成)。该字符串的第 i 个字符应为 '0',表示图中第 i 条边应从 ui 指向 vi;否则(即从 vi 指向 ui)应为 '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测评打分。不知道怎么写?