Codeforces Round #306 (Div. 2) D
2 seconds
256 megabytes
standard input
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.
The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.
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).
1
YES
2 1
1 2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
using namespace std; struct edge{
int u,v;
edge(){}
edge(int uu,int vv){u=uu,v=vv;}
}; vector<edge>ans; int main(){
int k;
while(scanf("%d",&k)!=EOF){
if(k%2==0){
puts("NO");
}
else{
if(k==1){
puts("YES");
printf("%d %d\n",2,1);
printf("%d %d\n",1,2);
continue;
}
ans.clear();
k+=2;
int g=k/2;
for(int i=0;i<k-1;i++){
for(int j=1;j<g;j++){
ans.push_back(edge(i,(i+j)%(k-1)));
ans.push_back(edge(i+k,(i+j)%(k-1)+k));
}
}
for(int i=1;i<k-1;i++){
ans.push_back(edge(i,k-1));
ans.push_back(edge(i+k,(k-1)+k));
}
ans.push_back(edge(0,k));
puts("YES");
int sz=ans.size();
printf("%d %d\n",k*2,sz);
for(int i=0;i<sz;i++){
printf("%d %d\n",ans[i].u+1,ans[i].v+1);
} }
}
return 0;
}
Codeforces Round #306 (Div. 2) D的更多相关文章
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造
E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- 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 ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs
B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
- Codeforces Round #306 (Div. 2) A B C
题目链接:http://codeforces.com/contest/550 A 暴力一发. 代码: #include <iostream> #include <stdio.h> ...
随机推荐
- SpringBoot入门之HelloWorld
1.SpringBoot简介 百度百科:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而 ...
- Java经典算法之插入排序(Insert Sort)
插入排序在局部有序的情况下比冒泡排序快一倍,比选择排序快一点. 那什么是插入排序,就是将局部有序的数据向右移动,将未排序的数据插到他的前面 下面我们来解析代码: 这里外层循环out变量从1开始向右移动 ...
- Oracle数据库初学者入门教程
Oracle数据库是相对于其他数据库来说比较难的一个.Oracle Database,又名Oracle RDBMS,简称Oracle.是甲骨文公司推出的一款关系数据库管理系统.Oracle数据库系统是 ...
- 洛谷2019 3月月赛 T3
题干 唯一AC T3 的大巨佬%%% 这题就是个大模拟吧. 题解
- MyBatis ((一对多和多对一配置)实现持久化操作 之二)
注: 此文中的实体类还是沿用上一章的Emp和Dept两个类 还是老样子,不细说 直接上代码 01.在emp.xml中 配置和Dept的多对一的相关信息 <?xml version=" ...
- Perforce 的基本使用教程
一.简介 P4是什么 二.基本使用方法 1.下载代码 下载最新代码 Get Latest Revision 下载指定commit代码 Get Revision 2. 检出代码 选择指定目录,右键 Ch ...
- mongo3.4 配置文件 注意事项
给mongo配置文件坑了好久,今天终于解决了.写个博客,庆祝一下. mongo3.4 版本,我是用YAML格式的配置文件. 一开始,配置之后,启动服务的时候,老是提示:“unrecognized op ...
- JS——大小写转化
<script> var str = 'JavaScript'; console.log(str.toUpperCase());//小写转大写 console.log(str.toLowe ...
- 控制台——屏蔽Ctrl+C快捷键对窗体的关闭功能
导入SetCtrlHandlerHandler API //定义处理程序委托 public delegate bool ConsoleCtrlDelegate(int ctrlType); //导入S ...
- nagios 插件ndoutils 安装配置
nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...