Codeforces 550D —— Regular Bridge——————【构造】

 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 verticesa 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。让你构造一个无向图,最少有一条桥,保证这个图中的所有顶点的度都为k。如果有这样的图,输出顶点数和边数,同时还有所有边的端点。

 

解题思路:首先我们证明k不能是偶数,假设结点u和v关于一条桥邻接,那么如果去掉该桥后,对于包含u结点的连通分量来说,只有u结点是奇数,那么这与连通分量中所有结点的度的和为偶数相矛盾,得证k只能为奇数。

    讨论k为奇数:我们假定结点1是由桥所连接的结点,那么想让1结点度数为k,那么就要有k-1个结点与1邻接,我们假设是2->k,这k-1个结点就算是行成完全图也不能保证度数为k,所以需要加一个结点k+1,让k+1先与2->k这k-1个结点相连,但是k+1结点的度才为k-1,所以我们仍然需要加结点k+2,让k+2也与2->k都连接,同时让k+1与k+2连接。保证了k+1和k+2度都为k。但是这时候2->k这k-1个结点度数都才为3。如果让2->k这k-1个结点行成完全图,那么每个结点会增加k-2个度,但是现在需要每个结点增加k-3个度,所以需要每个结点减少1个度。我们可以假设删去2 -> 3, 4 -> 5,6->7.....这些边。到这里我们的构造算法已经结束了。

    构造算法为:让1、k+1、k+2跟2->k这k-1个结点邻接,同时让2->k这k-1个结点形成完全图,但是删除env->env+1,env为2->k中所有偶数。同时桥所连接的那一边是对称的处理。

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1e5 + 300;
const int INF = 0x3f3f3f3f;
typedef long long  LL;
typedef unsigned long long ULL;
int main() {
    int k;
    scanf ( "%d", &k );
    if ( k == 1 ) {
        puts ("YES\n2 1\n1 2");
    }else if ( k % 2 == 0 ) {
        puts ( "NO" );
    }else {
        puts ( "YES" );
        printf ( "%d %d\n", 2*k + 4, k*(k+2) );
        for ( int i = 2; i <= k; i++ ) {
            printf ( "1 %d\n", i );
        }
        int nn = k + 2;
        for ( int i = 2; i <= k; i++ ) {
            printf("%d %d\n",i, k+1);
            printf("%d %d\n",i, k+2);
            for ( int j = i + 1; j <= k; j++ ) {
                if(i%2 == 0 && j == i+1) continue;
                printf ( "%d %d\n", i, j );
            }
        }
        printf ( "%d %d\n", k + 1, k + 2 );
        
        for ( int i = 2; i <= k; i++ ) {
            printf ( "%d %d\n", 1 + nn, i + nn );
        }
        for ( int i = 2; i <= k; i++ ) {
            printf("%d %d\n",i+nn, nn+k+1);
            printf("%d %d\n",i+nn, nn+k+2);
            for ( int j = i + 1; j <= k; j++ ) {
                if(i%2 == 0 && j == i+1) continue;
                printf ( "%d %d\n", i + nn, j + nn );
            }
        }
        printf ( "%d %d\n", k + 1 + nn, k + 2 + nn );
        printf ( "%d %d\n", 1, nn + 1 );
    }
    return 0;
}

  

 

转载于:https://www.cnblogs.com/chengsheng/p/5543684.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 内容概要 《计算机试卷1》是一份综合性的计算机基础和应用测试卷,涵盖了计算机硬件、软件、操作系统、网络、多媒体技术等多个领域的知识点。试卷包括单选题和操作应用两大类,单选题部分测试学生对计算机基础知识的掌握,操作应用部分则评估学生对计算机应用软件的实际操作能力。 ### 适用人群 本试卷适用于: - 计算机专业或信息技术相关专业的学生,用于课程学习或考试复习。 - 准备计算机等级考试或职业资格认证的人士,作为实战演练材料。 - 对计算机操作有兴趣的自学者,用于提升个人计算机应用技能。 - 计算机基础教育工作者,作为教学资源或出题参考。 ### 使用场景及目标 1. **学习评估**:作为学校或教育机构对学生计算机基础知识和应用技能的评估工具。 2. **自学测试**:供个人自学者检验自己对计算机知识的掌握程度和操作熟练度。 3. **职业发展**:帮助职场人士通过实际操作练习,提升计算机应用能力,增强工作竞争力。 4. **教学资源**:教师可以用于课堂教学,作为教学内容的补充或学生的课后练习。 5. **竞赛准备**:适合准备计算机相关竞赛的学生,作为强化训练和技能检测的材料。 试卷的目标是通过系统性的题目设计,帮助学生全面复习和巩固计算机基础知识,同时通过实际操作题目,提高学生解决实际问题的能力。通过本试卷的学习与练习,学生将能够更加深入地理解计算机的工作原理,掌握常用软件的使用方法,为未来的学术或职业生涯打下坚实的基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值