Codeforces 550D 构造

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 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,至少有一个桥。


题解:

首先n为偶数时候,先拆掉桥,那么其中一个分量的度为奇数,但是加入每条边度都会增加偶数,所以不可能。

对于奇数先把1判掉  然后可以弄出来一个对称图  对于其中一个连通图  加入两个点  将这两个点连接起来

加入一个点为割点  所以现在3个点的度都为1  再加入k-1个点  每个点连接这3个点  这3个点的度就完成了

现在解决k-1个点  每个点的度增加k-3  对于奇数跳过  对于偶数连过去


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int k;
	scanf("%d",&k);
	if(k==1){
		printf("YES\n2 1\n1 2\n");
		return 0;
	}
	if(!(k%2)){
		printf("NO\n");
	}
	else{
		printf("YES\n");
		int i,n=k+2;
		printf("%d %d\n",n*2,n*k);
		printf("%d %d\n",n-1,n-2);
		printf("%d %d\n",2*n-1,2*n-2);
		for(i=1;i<k;i++){
			printf("%d %d\n",i,n-1);
			printf("%d %d\n",i,n-2);
			printf("%d %d\n",i,n);
			printf("%d %d\n",i+n,2*n-1);
			printf("%d %d\n",i+n,2*n-2);
			printf("%d %d\n",i+n,2*n);
		}
		for(i=1;i<k;i++){
			int j;
			if(i%2)j=i+2;
			else j=i+1;
			for(;j<k;j++){
				printf("%d %d\n",i,j);
				printf("%d %d\n",i+n,j+n);
			}
		}
		printf("%d %d\n",n,n+n);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值