human
Construct a graph using N vertices whose shortest distance between K pair of vertices is 2 | Function to construct the simple and connected graph such that the distance between exactly K pairs of vertices is 2.
Stores maximum possible count of edges in a graph.
Base case.
Stores edges of a graph.
Connect all vertices of pairs ( i , j ).
Print first ( ( N - 1 ) + Max - K ) elements of edges [ ].
Driver code"
Solution in Python:
assistant
#Here is code to construct a graph using N vertices whose shortest distance between K pair of vertices is 2 and the other steps required.
 def constGraphWithCon ( N , K ) :
	Max = ( ( N - 1 ) * ( N - 2 ) ) // 2
	if ( K > Max ) :
		print ( - 1 )
		return
	ans = [ ]
	for i in range ( 1 , N ) :
		for j in range ( i + 1 , N + 1 ) :
			ans . append ( [ i , j ] )
	for i in range ( 0 , ( N - 1 ) + Max - K ) :
		print ( ans [ i ] [ 0 ] , ans [ i ] [ 1 ] , sep = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	N = 5
	K = 3
	constGraphWithCon ( N , K )