码迷,mamicode.com
首页 > 其他好文 > 详细

codeforce 550 D Regular Bridge

时间:2015-07-28 23:15:08      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

题意:建立一个连通图,它的所有点的度为k,且至少含有一个桥。


做法:先建立一个桥,再在桥两边建立两个度为k的连通图,通过这个桥连接在一起。


很显然k为偶数的时候无解。






#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%2==0)
	{
		puts("NO");
		return 0;
	}
	puts("YES");
	if(n==1)
	{
		printf("2 1\n1 2");
		return 0;
	}
	n++;
	cout<<2*n+2<<" ";
	if(n&1)
		cout<<n*n<<endl;
	else
		cout<<n*n-1<<endl;
	for(int i=1;i<=n;i++)
	{
		if(i<n-1)
		{
			cout<<i<<" "<<2*n+1<<endl;
			cout<<i+n<<" "<<2*n+2<<endl;
		}
		if(i==n-1)
		{
			cout<<i<<" "<<i+1<<endl;
			cout<<i+n<<" "<<i+1+n<<endl;
		}
		for(int j=i+1;j<=n;j++)
		{
			if(!((i&1)&&j==i+1))
			{
				cout<<i<<" "<<j<<endl;
				cout<<i+n<<" "<<j+n<<endl;
			}
		}
	}
	cout<<2*n+1<<" "<<2*n+2<<endl;
}

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).

Sample test(s)
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.



版权声明:本文为博主原创文章,未经博主允许不得转载。

codeforce 550 D Regular Bridge

标签:

原文地址:http://blog.csdn.net/stl112514/article/details/47112191

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!