前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cf550D. Regular Bridge(构造)

cf550D. Regular Bridge(构造)

作者头像
attack
发布2018-09-17 15:35:17
4100
发布2018-09-17 15:35:17
举报

题意

给出一个$k$,构造一个无向图,使得每个点的度数为$k$,且存在一个桥

Sol

神仙题

一篇写的非常好的博客:https://cloud.tencent.com/developer/article/1389569

我简单的来说一下构造过程

首先$n$是偶数的时候无解

奇数的时候:我们拿出两个点作为桥

先构建一条桥边,对于两个端点分别做同样操作:

新建$k−1$个点,每个点向端点连边

再新建$k−1$个点,每个点向相邻的点连边

对于两层点形成的二分图,两两之间连边

代码语言:javascript
复制
/*
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define LL long long 
#define ull unsigned long long 
#define rg register 
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS  *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int K, N, M;
void Build(int t) {
    for(int i = t + 1; i <= t + K - 1; i++)
        printf("%d %d\n", t, i);
    for(int i = t + 1; i <= t + K - 1; i++)
        for(int j = t + K ; j <= 2 * K + t - 2; j++)
            printf("%d %d\n", i, j);
    for(int i = K + t; i <= 2 * K + t - 2; i++)
        if(((t & 1) && (!(i & 1))) || ((!(t & 1)) && (i & 1))) printf("%d %d\n", i, i + 1);
}
main() {
    K = read();
    if(!(K & 1)) {puts("NO"); return 0;}
    puts("YES");
    N = (2 * (K - 1) + 1) * 2, M = N * K / 2;
    printf("%d %d\n", N, M);
    printf("%d %d\n", 1, N / 2 + 1);
    Build(1); 
    Build(N / 2 + 1);
    return 0;
}
/*
2 2 1
1 1
2 1 1
*/
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-09-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档