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> ...
随机推荐
- 使用GCD验证码倒计时
__block int timeout = 60; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY ...
- Echarts 出现不明竖线解决方案
Echarts出现了不明竖线,百思不得其解.去查相应的解决方案也没有找到. 后来自己点来点去,突然感觉像是上一个Echarts遗留的. 然后去Echarts官网看到了 clear()方法,这个方法可以 ...
- iOS CoreData 开发
新年新气象,曾经的妹子结婚了,而光棍的我决定书写博客~ 废话结束. 本人不爱使用第三方的东东,喜欢原汁原味的官方版本,本次带来CoreData数据存储篇~ 创建应用
- CxImage实现9PNG
CxImage* ScaleImageBy9PNG(CxImage *pRawImage, int nDstWidth,int nDstHeight) { if(NULL == pRawImage) ...
- THREE.js代码备份——webgl - geometry - dynamic(模拟海浪,通过时间(毫秒)来控制平面点的运动模拟海浪,鼠标控制写在另外的js中)
HTML: <!DOCTYPE html> <html lang="en"> <head> <title>three.js webg ...
- 体验SqlServer Express 2014
想使用SQLServer Express记录一些数据,但使用起来并不令人愉快.SQLServer Express是一个免费的可用数据库,但似乎设置了一些门槛,多少显得并不真心实意.抛开版本(技术)限制 ...
- Zabbix 客户端安装教程(第二篇)
Zabbix 客户端安装教程 blog地址:http://www.cnblogs.com/caoguo [root@localhost ~]# yum install -y gcc make [roo ...
- python发送文本邮件
#!/usr/bin/env python #coding=utf-8 #Author: Ca0Gu0 import time import smtplib from email.mime.text ...
- csrf漏洞利用
low csrf(cross-site-request forgery),跨站请求伪造. 测试网站 --http://localhost/vulnerability/csrf 修改密码,点击chang ...
- H5及微信中唤起app的解决方案
今天我们就来说说这个callapp-lib 我的接到的需求大概是这样的 如果检测到不是在app里面用webview打开的页面就会显示上面的立即打开按钮, 点击的话会判断是否在微信中, 如果在微信中打开 ...