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 verticesa 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。让你构造一个无向图,最少有一条桥,保证这个图中的所有顶点的度都为k。如果有这样的图,输出顶点数和边数,同时还有所有边的端点。

解题思路:首先我们证明k不能是偶数,假设结点u和v关于一条桥邻接,那么如果去掉该桥后,对于包含u结点的连通分量来说,只有u结点是奇数,那么这与连通分量中所有结点的度的和为偶数相矛盾,得证k只能为奇数。

    讨论k为奇数:我们假定结点1是由桥所连接的结点,那么想让1结点度数为k,那么就要有k-1个结点与1邻接,我们假设是2->k,这k-1个结点就算是行成完全图也不能保证度数为k,所以需要加一个结点k+1,让k+1先与2->k这k-1个结点相连,但是k+1结点的度才为k-1,所以我们仍然需要加结点k+2,让k+2也与2->k都连接,同时让k+1与k+2连接。保证了k+1和k+2度都为k。但是这时候2->k这k-1个结点度数都才为3。如果让2->k这k-1个结点行成完全图,那么每个结点会增加k-2个度,但是现在需要每个结点增加k-3个度,所以需要每个结点减少1个度。我们可以假设删去2 -> 3, 4 -> 5,6->7.....这些边。到这里我们的构造算法已经结束了。

    构造算法为:让1、k+1、k+2跟2->k这k-1个结点邻接,同时让2->k这k-1个结点形成完全图,但是删除env->env+1,env为2->k中所有偶数。同时桥所连接的那一边是对称的处理。

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1e5 + 300;
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef unsigned long long ULL;
int main() {
int k;
scanf ( "%d", &k );
if ( k == 1 ) {
puts ("YES\n2 1\n1 2");
}else if ( k % 2 == 0 ) {
puts ( "NO" );
}else {
puts ( "YES" );
printf ( "%d %d\n", 2*k + 4, k*(k+2) );
for ( int i = 2; i <= k; i++ ) {
printf ( "1 %d\n", i );
}
int nn = k + 2;
for ( int i = 2; i <= k; i++ ) {
printf("%d %d\n",i, k+1);
printf("%d %d\n",i, k+2);
for ( int j = i + 1; j <= k; j++ ) {
if(i%2 == 0 && j == i+1) continue;
printf ( "%d %d\n", i, j );
}
}
printf ( "%d %d\n", k + 1, k + 2 ); for ( int i = 2; i <= k; i++ ) {
printf ( "%d %d\n", 1 + nn, i + nn );
}
for ( int i = 2; i <= k; i++ ) {
printf("%d %d\n",i+nn, nn+k+1);
printf("%d %d\n",i+nn, nn+k+2);
for ( int j = i + 1; j <= k; j++ ) {
if(i%2 == 0 && j == i+1) continue;
printf ( "%d %d\n", i + nn, j + nn );
}
}
printf ( "%d %d\n", k + 1 + nn, k + 2 + nn );
printf ( "%d %d\n", 1, nn + 1 );
}
return 0;
}

  

Codeforces 550D —— Regular Bridge——————【构造】的更多相关文章

  1. codeforces #550D Regular Bridge 构造

    题目大意:给定k(1≤k≤100),要求构造一张简单无向连通图,使得存在一个桥,且每一个点的度数都为k k为偶数时无解 证明: 将这个图缩边双,能够得到一棵树 那么一定存在一个叶节点,仅仅连接一条桥边 ...

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

    D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  3. cf550D. Regular Bridge(构造)

    题意 给出一个$k$,构造一个无向图,使得每个点的度数为$k$,且存在一个桥 Sol 神仙题 一篇写的非常好的博客:http://www.cnblogs.com/mangoyang/p/9302269 ...

  4. Codeforces 550 D. Regular Bridge

    \(>Codeforces \space 550 D. Regular Bridge<\) 题目大意 :给出 \(k\) ,让你构造出一张点和边都不超过 \(10^6\) 的无向图,使得每 ...

  5. cf550D Regular Bridge

    Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...

  6. cf#306D. Regular Bridge(图论,构图)

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

  7. D. Regular Bridge 解析(思維、圖論)

    Codeforce 550 D. Regular Bridge 解析(思維.圖論) 今天我們來看看CF550D 題目連結 題目 給你一個\(k\le100\),請構造出一個至少有一個Bridge的,每 ...

  8. 「日常训练」Regular Bridge(Codeforces Round 306 Div.2 D)

    题意与分析 图论基础+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #defi ...

  9. Codeforces 1383D - Rearrange(构造)

    Codeforces 题面传送门 & 洛谷题面传送门 一道不算困难的构造,花了一节英语课把它搞出来了,题解简单写写吧( 考虑从大往小加数,显然第三个条件可以被翻译为,每次加入一个元素,如果它所 ...

随机推荐

  1. NLP常用开源/免费工具

    一些常见的NLP任务的开源/免费工具, *Computational Linguistics ToolboxCLT http://complingone.georgetown.edu/~linguis ...

  2. Spring MVC 基本配制

    WEB.XML 文件中的配制: <?xml version="1.0" encoding="UTF-8"?> <web-app id=&quo ...

  3. ASP.NET MVC 如何使用自定义过滤器(筛选器)

    继承*****Attribute(筛选器三种具体类)-->重写方法-->标记在控制器 或者 方法上面 或者 在FilterConfig中Add [类名(类属性 = 值)]还有[AllowA ...

  4. Re:从零开始的Spring Security Oauth2(二)

    本文开始从源码的层面,讲解一些Spring Security Oauth2的认证流程.本文较长,适合在空余时间段观看.且涉及了较多的源码,非关键性代码以…代替. 准备工作 首先开启debug信息: l ...

  5. [Cocos2d-x for WP8学习笔记] 一些基本概念,建立自己的启动界面

    流程控制:场景是相对不变的游戏元素集合,游戏在场景间的切换就是流程控制. 场景.层和精灵:它们是不同层次的游戏元素.通常,场景包含层,层包含精灵,场景与层是其他游戏元素的容器,而精灵是展示给玩家的图形 ...

  6. luogu1357花园(矩阵运算)(状压DP)

    不得不说本蒻做这个题目的时候内心是很蒙蔽的qwq 推了规律找错了结果还没有暴力的分数高qwq...... 开数组\(f[i][j]\)来记录前i个花圃,(这里运用到状压的思想)其中最近的m个的状态(二 ...

  7. leecode刷题(11)-- 反转字符串

    leecode刷题(11)-- 反转字符串 反转字符串 描述: 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh& ...

  8. CentOS6.9 ARM虚拟机扩容系统磁盘

    由于扩容磁盘的操作非同小可,一旦哪一步出现问题,就会导致分区损坏,数据丢失等一系列严重的问题,因此建议:在进行虚拟机分区扩容之前,一定要备份重要数据文件,并且先在测试机上验证以下步骤,再应用于您的生产 ...

  9. spring quartz 的定时器cronExpression表达式写法(转载)

    转载来源:https://zhidao.baidu.com/question/240797777248343764.html====================================== ...

  10. Python3学习札记

    1.- (按位取反) x的按位取反结果为-(x+1)   e.g. -5输出-6 更多细节,阅:http://stackoverflow.com/a/11810203 2.DocString约定 为一 ...