zoukankan      html  css  js  c++  java
  • cf#306D. Regular Bridge(图论,构图)

    D. Regular Bridge
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.

    Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph doesn't exist.

    Input

    The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.

    Output

    Print "NO" (without quotes), if such graph doesn't exist.

    Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines.

    The description of the made graph must start with numbers n and m — the number of vertices and edges respectively.

    Each of the next m lines must contain two integers, a and b (1 ≤ a, b ≤ na ≠ b), that mean that there is an edge connecting the vertices aand b. A graph shouldn't contain multiple edges and edges that lead from a vertex to itself. A graph must be connected, the degrees of all vertices of the graph must be equal k. At least one edge of the graph must be a bridge. You can print the edges of the graph in any order. You can print the ends of each edge in any order.

    The constructed graph must contain at most 106 vertices and 106 edges (it is guaranteed that if at least one graph that meets the requirements exists, then there also exists the graph with at most 106 vertices and at most 106 edges).

    Sample test(s)
    input
    1
    output
    YES
    2 1
    1 2

    Let's prove that there is no solution for even k.

    Suppose our graph contains some bridges, k = 2s (even), all degrees are k. Then there always exists strongly connected component that is connected to other part of the graph with exactly one bridge.

    Consider this component. Let's remove bridge that connects it to the remaining graph. Then it has one vertex with degree k - 1 = 2s - 1and some vertices with degrees k = 2s. But then the graph consisting of this component will contain only one vertex with odd degree, which is impossible by Handshaking Lemma.

    Let's construct the answer for odd k. Let k = 2s - 1.

    For k = 1 graph consisting of two nodes connected by edge works.

    For k ≥ 3 let's construct graph with 2k + 4 nodes. Let it consist of two strongly connected components connected by bridge. Enumerate nodes of first component from 1 to k + 2, second component will be the same as the first one.

    Let vertex 1 be connected to the second component by bridge. Also connect it with k - 1 edges to vertices 2, 3, ..., k. Connect vertices2, 3, ..., k to each other (add all possible edges between them), and then remove edges between every neighbouring pair, for example edges 2 - 3, 4 - 5, ..., (k - 1) - k.

    Then we connect vertices 2, 3, ..., k with vertices k + 1 and k + 2. And finally add an edge between nodes k + 1 and k + 2.

    Build the second component in the similar manner, and add a bridge between components. Constructed graph has one bridge, all degrees of k and consists of O(k) nodes and O(k2) edges.

    Complexity of the solution — O(k2).

     
  • 相关阅读:
    老司机心得之时间管理"入坑"
    shell的字符串和数字的转化(数字自动做字符串处理,变量名做字符串输出用单引号)
    shell的date命令:使用方法,以及小时、分钟的计算
    一篇详细的linux中shell语言的字符串处理
    linux的string操作(字符串截取,长度计算)
    linux下数学运算器:expr命令(shell中完成数学运算)
    shell脚本格式的几点注意:格式严格,空格不能随便出现(一写就记不住)
    vim的颜色修改,高亮设置。
    pyhton exit
    python判断类型:想知道一个对象(实例或者变量)是什么类型,什么结构的
  • 原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4558663.html
Copyright © 2011-2022 走看看