The 2020 ICPC 澳门 Fixing Networks(构造)
链接
题意:给出n个点,要求构造c个集合的无向图,每个点的度数是d,输出构造方法
思路:容易想到的是再环上构造,因为环才能实现每个点的度数相同,首先是当
c
∗
(
d
+
1
)
>
n
c*(d+1)>n
c∗(d+1)>n,那这时是无解的然后在一副无向图中,度数和一定是偶数,所以如果
n
%
2
&
&
d
%
2
n \% 2\&\&d\%2
n%2&&d%2那这时也是无解的,特判d是
1
/
0
1/0
1/0的情况,剩下的情况是用每个集合
d
+
1
d+1
d+1个点构造
c
−
1
c-1
c−1个集合,剩下的单独构造,我们可以把每个点与他前
[
d
/
2
]
[d/2]
[d/2]和后
[
d
/
2
]
[d/2]
[d/2]连接,假设d是奇数,我们就在对于每个点多连接与他相对的点。
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n, d, c;
cin >> n >> d >> c;
if (d == 0) {
if (c != n) {cout << "No"; return 0;}
cout << "Yes"; return 0;
}
if (d == 1) {
if (n & 1) {cout << "No"; return 0;}
if (c != n / 2) {cout << "No" ; return 0;}
cout << "Yes" << endl;
for (int i = 1; i <= n; i++) {
cout << i + ((i & 1) ? 1 : -1) << endl;
}return 0;
}
if (c * (d + 1) > n) {cout << "No"; return 0;}
if ((n & 1) && (d & 1)) {cout << "No" ; return 0;}
cout << "Yes" << endl;
int a = n / (d + 1);
for (int i = 0; i < c - 1; i++) {
for (int j = 1; j <= d + 1; j++) {
for (int k = 1; k <= d + 1; k++) {
if (j == k) continue;
cout << k + i * (d + 1) << ' ' ;
}cout << endl;
}
}
int b = n - (d + 1) * (c - 1);
int cc = d / 2;
for (int i = 1; i <= b; i++) {
priority_queue<int, vector<int>, greater<int> > ans;
for (int j = 1; j <= cc; j++) {
int cnt = (i + j) % b + n - b;
if (i + j == b) {cnt = n;}
ans.push(cnt);
}
for (int j = 1; j <= cc; j++) {
int cnt = i - j + n - b;
if (i - j <= 0) {cnt = b - (j - i) + n - b;}
ans.push(cnt);
}
if (d % 2 == 1) {int cnt = (i + b / 2) % b + n - b; if (i + b / 2 == b) cnt = n; ans.push(cnt);}
while (!ans.empty()) {cout << ans.top() << ' '; ans.pop();}cout << endl;
}
return 0;
}