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 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 . All the integers , , , are used in labeling (note that you do not need to minimize or maximize the value of );
- For each vertex of the given cactus, the labels of edges incident to the vertex should be different and should form an interval of consecutive integers.
An edge in the graph is called if the deletion of that edge increases the number of connected components of the graph. A 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 and (, ) --- the number of vertices and edges in the cactus. Each of the next lines contains two integers and (; ) --- 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 . Otherwise, in the first line output the single word . In the second line output an integer () --- the number of different labels. In the third line output should contain integers (, ) --- 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