思路:假如b=2,中心为A,重心为B,那么A-X-B,为了令A和B合法,必须添加节点X-X-A-X-B-(XXX),这就是b=2时需要的最少节点数,B每增大1就要增加4个节点;当b=0和b=1时有一些细节要处理。
# include
using namespace std;
int main()
{int t, n, b;scanf("%d",&t);while(t--){scanf("%d%d",&n,&b);if(b &#61;&#61; 0){if(n <3){puts("NO");continue;}puts("YES");for(int i&#61;2; i<&#61;n; &#43;&#43;i)printf("1 %d\n",i);}else if(b &#61;&#61; 1){if(n &#61;&#61; 2){printf("YES\n1 2\n");continue;}if(n &#61;&#61; 3){puts("NO");continue;}printf("YES\n1 2\n2 3\n3 4\n");for(int i&#61;5; i<&#61;n; &#43;&#43;i)printf("3 %d\n",i);}else{if((b-1)*4&#43;4 > n){puts("NO");continue;}puts("YES");int p &#61; 2*b&#43;1;for(int i&#61;1; i}