how to reduce the time complexity of this code?

I have a graph G=(V,E). A list of nodes NODE subset of V. I want to find out all the neighbor nodes of each node in NODE and add edge if those neighbors have distance greater than 2. Can anyone here please help me to reduce the time complexity of this code:

import networkx as nx import random  G = nx.erdos_renyi_graph(30, 0.05)  node=[] for j in range(5):          node.append(random.randint(1,30))  for i in node:     lst=list(G.neighbors(i))     if(len(lst)>1):          for j in range(len(lst)):              for k in range(j+1,len(lst)):                  if(len(nx.shortest_path(G,lst[j],lst[k]))>2):                      G.add_edge(lst[j],lst[k])