[ARC161D] Everywhere is Sparser than Whole (Construction) 题解
题目链接
前言
第一次做出 ARC 的 D 题欸。
updata 2023/6/6 17:40 修正一个明显的错误。
题解
首先,不难发现,若
接着,可以证明出,只要
证明:
设一个点
则若要使有解,就必须满足
不难想到一种可以构造一个每一个点的度相同的图,如何构造?其实,这里可以用迭代
代码
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair <int,int> PII;
int n,d;
int main () {
cin >> n >> d;
if (d * n > (LL)n * (n - 1) / 2) {
puts ("No");
return 0;
}
puts ("Yes");
for (int len = 1;len <= d;len++) {
for (int i = 1;i <= n;i++) {
int ni = (i + len - 1) % n + 1;
cout << i << ' ' << ni << endl;
}
}
return 0;
}