22629_K-GraphOddity

2022-5-16 18:22| 发布者: Hocassian| 查看: 21| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506799707000-Problem List-采集的数据-后羿采集器.html

Pro.ID

22629

Title

K-Graph Oddity

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22629

AC

7

Submit

9

Ratio

77.78%

时间&空间限制

  • Time Limit: 6000/6000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others)
  • 描述

    You are given a connected undirected graph with an odd number of vertices. The degree of the vertex, by definition, is the number of edges incident to it. In the given graph the degree of each vertex does not exceed an odd number k. Your task is to color the vertices of this graph into at most k distinct colors, so that the colors of any two adjacent vertices are distinct.

    The pictures below show two graphs. The first one has 3 vertices and the second one has 7 vertices. In both graphs degrees of the vertices do not exceed 3 and the vertices are colored into at most 3 different colors marked as '', '', and ''.

    输入

    The first line of the input file contains two integer numbers n and m, where n is the number of vertices in the graph ( 3 ≤ n ≤ 9999, n  is odd ), m is the number of edges in the graph ( 2 ≤ m ≤ 100 000 ). The following m lines describe edges of the graph, each edge is described by two integers ai , bi ( 1 ≤ ai, bin, aibi) — the vertex numbers connected by this edge. Each edge is listed at most once. The graph in the input file is connected, so there is a path between any pair of vertices.

    输出

    Description

    You are given a connected undirected graph with an odd number of vertices. The degree of the vertex, by definition, is the number of edges incident to it. In the given graph the degree of each vertex does not exceed an odd number k. Your task is to color the vertices of this graph into at most k distinct colors, so that the colors of any two adjacent vertices are distinct.

    The pictures below show two graphs. The first one has 3 vertices and the second one has 7 vertices. In both graphs degrees of the vertices do not exceed 3 and the vertices are colored into at most 3 different colors marked as '', '', and ''.

    Input

    The first line of the input file contains two integer numbers n and m, where n is the number of vertices in the graph ( 3 ≤ n ≤ 9999, n  is odd ), m is the number of edges in the graph ( 2 ≤ m ≤ 100 000 ). The following m lines describe edges of the graph, each edge is described by two integers ai , bi ( 1 ≤ ai, bin, aibi) — the vertex numbers connected by this edge. Each edge is listed at most once. The graph in the input file is connected, so there is a path between any pair of vertices.

    Output

    On the first line of the output file write a single integer number k — the minimal odd integer number, such that the degree of any vertex does not exceed k. Then write n lines with one integer number ci ( 1 ≤ cik ) on a line that denotes the color of i-th vertex. The colors of any two adjacent vertices must be different. If the graph has multiple different colorings, print any of them. At least one such coloring always exists.

    Sample Input

    Sample #1
    3 2
    1 3
    3 2

    Sample #2
    7 8
    1 4
    4 2
    2 6
    6 3
    3 7
    4 5
    5 6
    5 2

    Sample Output

    Sample #1
    3
    1
    1
    2

    Sample #2
    3
    1
    1
    1
    2
    3
    2
    2

    Source

    样例输入

    Sample #1
    3 2
    1 3
    3 2

    Sample #2
    7 8
    1 4
    4 2
    2 6
    6 3
    3 7
    4 5
    5 6
    5 2

    样例输出

    Sample #1
    3
    1
    1
    2

    Sample #2
    3
    1
    1
    1
    2
    3
    2
    2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部