Codeforces Round #306 (Div. 2)D

D. Regular Bridge
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 ≤ 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).

Examples
input
1
output
YES
2 1
1 2
Note
In the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.

这个题偶数不行
奇数处理起来需要分成两边

链接桥的那个需要链接k-1个点
然后底下再多两个点

每个点都连那k-1个点
然后多出来的俩互联

偶数不行就是因为没法处理中间那k-1个

其实很早就想到加两个点了
但是没考虑到奇数偶数

所以忽略过去了

是个教训…

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int k;
void shuchu(int tou, int wei)
{
    int nayiquan = k - 1;
    for (int a = tou;a <= wei - 3;a++)
    {
        for (int b = a;b <= wei - 3;b++)
        {
            if (a == b||abs(a-b)==(k-1)/2)continue;
            cout << a << " " << b << endl;
        }
        cout << a << " " << wei - 1<<endl;
        cout << a<<" " << wei - 2 << endl;
        cout << a << " " << wei << endl;
    }
    cout << wei - 1 << " " << wei - 2 << endl;
}
int main()
{
    cin >> k;
    if (k == 1)
    {
        cout << "YES"<<endl;
        cout << "2 1" << endl<<"2 1"<<endl;
        return 0;
    }
    if (k == 2)
    {
        cout << "NO" << endl;
        return 0;
    }
    if (k == 3)
    {
        cout << "YES" << endl;
        cout << "10 15" << endl;
        cout << "1 2" << endl << "1 3" << endl << "1 4" << endl << "2 4" << endl;
        cout << "3 2" << endl << "4 5" << endl << "3 5" << endl << "5 10" << endl;
        cout << "10 6" << endl << "10 7" << endl << "6 9" << endl << "6 8" << endl;
        cout << "7 8" << endl << "7 9" << endl << "8 9" << endl;
        return 0;
    }
    if (k % 2 == 0)
    {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    cout << 2 * k+4 << " " << 2*(3*(k-1)+1+((k-3)/2)*(k-1))+1 << endl;
    cout << k+2 << " " << 2*k + 4<<endl;
    shuchu(1, k + 2);
    shuchu(k + 3, 2 * k + 4);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值