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).

     
  • 相关阅读:
    c#操作ElasticSearch5详解
    消息推送服务
    Elasticsearch5.0.1 + Kibana5.0.1 + IK 5.0.1
    C#使用ES
    C# 开发人员的函数式编程
    Swagger文档转Word
    Spring Security OAuth2 Demo -- good
    is not eligible for getting processed by all BeanPostProcessors
    成功都一样,失败各不同;失败的项目也许值得你警醒
    java.exe进程来源排查录
  • 原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4558663.html
Copyright © 2011-2022 走看看