http://codeforces.com/problemset/problem/990/D
Meaning of the questions:
A configuration of order n simple undirected graph G, such that the number of communication branches to a, and the number of connected components of its complement graph b.
answer:
At first glance the title, and a look ignorant, ah? It makes me how to build map? ? ?
Or vegetables ah, look at someone else's problem solution learn from it. . .
Reference to: https://www.cnblogs.com/siuginhung/p/9172602.html
This is a configuration problem.
For an n-order simple undirected graph , if this does not communicate FIG G, it is the complement of FIG communication.
prove:
First, in a simple non-directed graph , if the node G in U, V ( U ≠ V) is not connected, then its complement figures, U, V bound communication.
FIG G = <V, E> is divided into k-branch communication, Gi of = <Vi, Ei>, I = 1,2, ..., k. In V to take any two points U, V ( U ≠ V).
若u∈Vi,v∈Vj,且i≠j,则u、v在图G中不连通,则u、v必然在其补图中连通;
若u,v∈Vi,则必然存在w∈Vj,且i≠j,使得u、w和v、w在补图中连通。
于是,在题中,a、b中至少有一个为1。
接下来构造连通分支:若一个n阶简单无向图有k(k≥2)个连通分支,则可以构造其连通分支分别为{1},{2},...,{k-1},{k,k+1,...,n}。
代码如下:
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <sstream> 13 const int INF=0x3f3f3f3f; 14 typedef long long LL; 15 #define Bug cout<<"---------------------"<<endl 16 const int mod=1e9+7; 17 const int maxn=2e5+10; 18 using namespace std; 19 20 int G[1005][1005]; 21 22 int main() 23 { 24 int n,a,b; 25 scanf("%d %d %d",&n,&a,&b); 26 if((a!=1&&b!=1)||(n==2||n==3)&&(a==1&&b==1)) 27 printf("NO\n"); 28 else 29 { 30 printf("YES\n"); 31 if(a==1) 32 { 33 for(int i=1;i<=n;i++) 34 { 35 G[i][i]=0; 36 for(int j=i+1;j<=n;j++) 37 G[i][j]=G[j][i]=1; 38 } 39 for(int i=b;i<n;i++) 40 G[i][i+1]=G[i+1][i]=0; 41 } 42 else 43 { 44 memset(G,0,sizeof(G)); 45 for(int i=a;i<n;i++) 46 { 47 G[i][i+1]=G[i+1][i]=1; 48 } 49 } 50 for(int i=1;i<=n;i++) 51 { 52 for(int j=1;j<=n;j++) 53 printf("%d",G[i][j]); 54 printf("\n"); 55 } 56 } 57 return 0; 58 }