D. Graph And Its Complement[构造题]

D. Graph And Its Complement

题意:给定a,b.要求构造一个邻接矩阵,对应的图中,有a个联通块  ; 对应的补图有b个联通块

思路:

假设a>1,那么b一定为1.说明a,b中至少有一个是1.特判构造

a>1,前a-1个独立,为a-1个联通块;[a+1,n]顶点为一个联通块

a==1,b>1.构造补图的,再返回来

a==1,b==1.n=1成立,n=2,n=3不成立.n>=4,就是一个链

#include
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(3)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=1e3+3;
const int MOD=1e9+7;
const ll INF=1e18+8;
int ans[N][N];
int main(void){
    FAST_IO;
    int n,a,b;
    cin >>n >> a>>b;
    if(a!=1&&b!=1){
        cout <<"NO"<

你可能感兴趣的:(构造题)