• Codeforces Round #306 (Div. 2) D. Regular Bridge 构造


    D. Regular Bridge

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/550/problem/D

    Description

    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 ≤ n, a ≠ b), that mean that there is an edge connecting the vertices a and 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 Input

    1

    Sample Output

    YES
    2 1
    1 2

    HINT

    题意

    让你构造度数为k的正则图,然后要求里面至少有一条边是桥

    题解:

    构造,乱搞……

    构造出一个bra图……

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 2000001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    int main()
    {
        int K;
        cin >>K;
        if(K%2==0)
        {
            cout << "NO";
            return 0;
        }
        cout << "YES
    ";
        printf("%d %d
    ", K*4-2, (K*4-2)*K/2);
        printf("%d %d
    ", 1, (K*2-1)+1);
        for(int i = 2; i <= K; ++i)
        {
            printf("%d %d
    ", 1, i);
            printf("%d %d
    ", (K*2-1)+1, (K*2-1)+i);
            for(int j = K+1; j <= 2*K-1; ++j)
            {
                printf("%d %d
    ", i, j);
                printf("%d %d
    ", (K*2-1)+i, (K*2-1)+j);
            }
        }
        for(int i = K+1; i <= 2*K-1; i += 2)
        {
            printf("%d %d
    ", i, i+1);
            printf("%d %d
    ", (K*2-1)+i, (K*2-1)+i+1);
        }
    }
  • 相关阅读:
    Flask把变量注册到模板中
    $.each与$(data).each区别
    【Python备忘】python判断文件和文件夹是否存在
    ISP图像质量自动化测试方法
    使用微软的(how-old.net)构建智能门店管理系统
    在virtualenv中安装libxml2和libxslt
    Python 装饰器学习以及实际使用场景实践
    tensorflow零起点快速入门(4) --入门常用API
    tensorflow零起点快速入门(3)
    树莓派和STM32通过USB和串口通信记录
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4553604.html
Copyright © 2020-2023  润新知