codeforce 550 D Regular Bridge

题意:建立一个连通图,它的所有点的度为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.

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

时间: 2024-08-02 16:44:41

codeforce 550 D Regular Bridge的相关文章

cf550D Regular Bridge

Regular Bridge 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 un

Codeforces550D:Regular Bridge

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-regu

codeforces #550D Regular Bridge 构造

题目大意:给定k(1≤k≤100),要求构造一张简单无向连通图,使得存在一个桥,且每一个点的度数都为k k为偶数时无解 证明: 将这个图缩边双,能够得到一棵树 那么一定存在一个叶节点,仅仅连接一条桥边 那么这个边双内部全部点度数之和为偶数 除掉连出去的桥边外度数之和为奇数 故不合法 然后k为奇数的时候我们仅仅须要构造两个对称的边双被一条桥边连接的图即可了 因为每一个点度数为k.因此每一边至少须要k+1个点 可是k+1个点奇偶性不合法.因此每一边至少须要k+2个点 如今问题转化成了给定一个度数数组

cf550D. Regular Bridge(构造)

题意 给出一个$k$,构造一个无向图,使得每个点的度数为$k$,且存在一个桥 Sol 神仙题 一篇写的非常好的博客:http://www.cnblogs.com/mangoyang/p/9302269.html 我简单的来说一下构造过程 首先$n$是偶数的时候无解 奇数的时候:我们拿出两个点作为桥 先构建一条桥边,对于两个端点分别做同样操作: 新建$k−1$个点,每个点向端点连边 再新建$k−1$个点,每个点向相邻的点连边 对于两层点形成的二分图,两两之间连边 /* */ #include<io

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

题意与分析 图论基础+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #define fi first #define se second #define ZERO(x) memset((x), 0, sizeof(x)) #define ALL(x) (x).begin(),(x).end() #define rep(i, a, b) for (repType i = (a); i &

Codeforces Round #306 (Div. 2) D.E. 解题报告

D题:Regular Bridge 乱搞.构造 这题乱搞一下就行了.构造一个有桥而且每个点的度数都为k的无向图.方法很多,也不好叙述.. 代码如下: #include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <stack> #include <map> #include <algorithm> #define INF 0x

Codeforces Round #306 (Div. 2) (构造)

A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全,最后只能很蠢的暴力,把所有的AB和BA的位置求出来,能有一对AB和BA不重叠即可. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 char a[100005]; 5 vector<int> ab; 6 vector<i

Intel Ivy Bridge Microarchitecture Events

This is a list of all Intel Ivy Bridge Microarchitecture performance counter event types. Please see Intel Architecture Developer's Manual Volume 3B, Appendix A and Intel Architecture Optimization Reference Manual (730795-001). Name Description Count

Intel Sandy Bridge Microarchitecture Events

This is a list of all Intel Sandy Bridge Microarchitecture performance counter event types. Please see Intel Architecture Developer's Manual Volume 3B, Appendix A and Intel Architecture Optimization Reference Manual (730795-001) Name Description Coun