cf990d Graph And Its Complement

OI 思维
文章目录

有大于 $1$ 个联通块时,补图显然是一大个联通块。

特判一下 $a=b=1$ 时。此时 $n=1$ 或 $n \geq 4$ 有解(比如一条链)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cstdio>
using namespace std;
int n, a, b, c[1005][1005];
void myOut(){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++)
printf("%d", c[i][j]);
printf("\n");
}
}
int main(){
cin>>n>>a>>b;
if(a==1 && b==1){
if(n==2 || n==3) printf("NO\n");
else{
printf("YES\n");
for(int i=1; i<n; i++)
c[i][i+1] = c[i+1][i] = 1;
myOut();
}
}
else if(a==1){
for(int i=1; i<n-b+1; i++)
c[i][i+1] = c[i+1][i] = 1;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++)
c[i][j] = 1 - c[i][j];
c[i][i] = 0;
}
printf("YES\n");
myOut();
}
else if(b==1){
for(int i=1; i<n-a+1; i++)
c[i][i+1] = c[i+1][i] = 1;
printf("YES\n");
myOut();
}
else printf("NO\n");
return 0;
}