luogu#P12094. [NERC2024] Cactus without Bridges

[NERC2024] Cactus without Bridges

题目描述

Caroline asked you for help in solving a cactus problem one year ago. During the last year, she researched extensively about cactuses. Today, she is the one presenting the problem.

You are given a cactus without bridges\textbf{cactus without bridges} and also the length of each odd simple cycle is greater than or equal to the number of odd simple cycles in cactus. Your task is to answer whether it's possible to label the cactus edges with positive integers such that the following conditions are satisfied:

  • Let's define the maximum label with tt. All the integers 11, 22, \ldots, tt are used in labeling (note that you do not need to minimize or maximize the value of tt);
  • For each vertex vv of the given cactus, the labels of edges incident to the vertex vv should be different and should form an interval of consecutive integers.

An edge in the graph is called bridge\textit{bridge} if the deletion of that edge increases the number of connected components of the graph. A cactus\textit{cactus} is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. Multiedges (multiple edges between a pair of vertices) and loops (edges that connect a vertex to itself) are not allowed in a cactus.

输入格式

The first line contains two integers nn and mm (3n1053 \le n \le 10^5, nm3(n1)2n \le m \le \lfloor \frac{3(n - 1)}{2} \rfloor) --- the number of vertices and edges in the cactus. Each of the next mm lines contains two integers uu and vv (1u,vn1 \le u, v \le n; uvu \ne v) --- the edges of the cactus. The given cactus satisfies all constraints from the problem statement.

输出格式

If finding the labeling satisfying the problem's conditions is impossible, output the single line with the word NO\tt{NO}. Otherwise, in the first line output the single word YES\tt{YES}. In the second line output an integer tt (1tm1 \leq t \leq m) --- the number of different labels. In the third line output should contain mm integers cic_i (1im1 \leq i \leq m, 1cit1 \leq c_i \leq t) --- the labels of the edges.

5 5
1 2
2 3
3 4
4 5
5 1
NO
8 10
1 2
2 3
1 3
1 4
1 5
4 5
5 6
6 7
7 8
8 5
YES
4
1 2 3 2 4 3 1 2 3 2