# 题目

## 数据范围

5 ≤ n ≤ 50 , n − 1 ≤ m ≤ 2 n − 1 5\leq n\leq50,n-1\leq m\leq 2n-1

# 题解

## 题目分析

1. m = n − 1 m=n-1 ，答案是1，构造方法是一条链
2. n ≤ m < n + ⌈ n 2 ⌉ n\leq m<n+\lceil\dfrac{n}{2}\rceil ，答案是2，先构造一个环，然后连环的直径
3. m ≥ n + ⌈ n 2 ⌉ m\ge n+\lceil\dfrac{n}{2}\rceil ，答案是3，先构造一个环，然后连所有直径，然后随便连没连的点

# Code

#include<cstdio>
using namespace std;
int n,m;
bool b[55][55];
int main()
{
freopen("bondorudo.in","r",stdin);
freopen("bondorudo.out","w",stdout);
scanf("%d%d",&n,&m);
if (m==n-1)
{
printf("1\n");
for (int i=1;i<=m;++i)
printf("%d %d\n",i,i+1);
fclose(stdin);
fclose(stdout);
return 0;
}
if (m>=n&&m<n+((n-1)>>1)+1)
{
printf("2\n");
for (int i=1;i<n;++i)
printf("%d %d\n",i,i+1);
printf("%d 1\n",n);
m-=n;
for (int i=1;i<=m;++i)
printf("%d %d\n",i,(i+(n>>1)-1)%n+1);
fclose(stdin);
fclose(stdout);
return 0;
}
if (m>=n+((n-1)>>1)+1)
{
printf("3\n");
for (int i=1;i<n;++i)
printf("%d %d\n",i,i+1),b[i][i+1]=true;
printf("%d 1\n",n);
b[n][1]=true;
m-=n;
for (int i=1;i<=((n-1)>>1)+1;++i)
printf("%d %d\n",i,(i+(n>>1)-1)%n+1),b[i][(i+(n>>1)-1)%n+1]=true;
m-=((n-1)>>1)+1;
for (int i=1;i<=n;++i)
b[i][i]=true;
while (m--)
{
bool bj=false;
for (int i=1;i<=n;++i)
{
for (int j=i+1;j<=n;++j)
if (!b[i][j])
{
printf("%d %d\n",i,j);
b[i][j]=bj=true;
break;
}
if (bj) break;
}
}
}
fclose(stdin);
fclose(stdout);
return 0;
}


12-02 48

12-04 35
01-29
03-25
10-27
01-08