using
System;
using
System.Collections.Generic;
class
GFG
{
public
class
pair
{
public
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
void
connected_graph(
int
n,
int
k)
{
if
(k > (n - 1) * (n - 2) / 2)
{
Console.WriteLine(-1);
return
;
}
bool
[,]isEdge =
new
bool
[n, n];
for
(
int
i = 0; i < n; i++)
{
for
(
int
j = i + 1; j < n; j++)
isEdge[i, j] =
true
;
}
int
cnt = 0;
for
(
int
i = 1; i < n; i++)
{
for
(
int
j = i + 1; j < n; j++)
{
if
(cnt < k)
{
isEdge[i, j] =
false
;
cnt++;
}
}
}
List<pair> vec =
new
List<pair>();
for
(
int
i = 0; i < n; i++)
{
for
(
int
j = i + 1; j < n; j++)
{
if
(isEdge[i, j])
vec.Add(
new
pair(i, j));
}
}
Console.WriteLine(vec.Count);
for
(
int
i = 0; i < vec.Count; i++)
{
Console.WriteLine(vec[i].first + 1 +
" "
+ (vec[i].second + 1));
}
}
public
static
void
Main(String[] args)
{
int
n = 5, k = 3;
connected_graph(n, k);
}
}