博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 550D. Regular Bridge 构造
阅读量:5914 次
发布时间:2019-06-19

本文共 2357 字,大约阅读时间需要 7 分钟。

求一个图,每一个点的度数都为K并且必须至少要有一个桥.

构造题:

仅仅有k为奇数的时候有解, 构造这种一个图,左边一团有 k+1 个点 , 右边一团也有 k+1 个点, 中间经过 m1 , m2 连着一个桥.

假设左右两团是全然图,则每一个点的度数都为k, 如今考虑怎样通过m1,m2连接起来而又不改变度数.

显然这个图是对称的,仅仅考虑左边和点m1,m1和m2是一个桥,要连一条边,m1 和左边的团某个点A要连在一起,又要连一条边,这时A点的度数多了,要和团里的其它点B断掉一条边,为了保持B的度数不变,B再连一条边到m1,这时m1的度就至少为3了,然后将m1的度补全. 每次从左边团中删掉一条边,然后将这条边的两个点连到m1上就能够了.m1的度每次添加2,所以假设k为奇数的话都能够用这个方案构造出来.

D. 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 aand 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
YES2 11 2
Note

In the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.

import java.util.*;import java.math.*;public class Main{	int k,midl,midr;	boolean[][] edge = new boolean[330][330];	boolean[] used = new boolean[330];	void cut_and_link(int from,int to,int goal)	{		int tk=k-3;		while(tk>0)		{			boolean flag=false;			for(int i=from;i

转载地址:http://gggpx.baihongyu.com/

你可能感兴趣的文章
Ubuntu Server 语言环境变量改为英文
查看>>
数据库存储图片读取
查看>>
企业级nginx.conf优化参考模板
查看>>
我的友情链接
查看>>
[转]理解Python的双下划线命名
查看>>
初识Linux_3
查看>>
继承与静态成员
查看>>
linux VPN 多IP出口 iptables设置
查看>>
测试计算机是小端存储还是大端存储
查看>>
c++ 写时拷贝
查看>>
Linux下搭建SMB文件共享服务,Linux/Windows互联互通
查看>>
2013年七月GBin1月刊
查看>>
MaxCompute 学习计划(一)
查看>>
数据让生意更简单,网聚宝创业团队利用数加快速打造核心业务竞争力,在激烈的市场竞争中弯道超车。...
查看>>
聊聊storm TridentWindowManager的pendingTriggers
查看>>
一个复杂的Linux下的socket程序
查看>>
tigase 集群配置
查看>>
组策略部署软件之一:软件分发概论与部署MSI程序包
查看>>
JSP技术
查看>>
python装载模块的顺序
查看>>