def ramsey_R2(G):
 if (not G):
  return (set(), set())
 node = arbitrary_element(G)
 nbrs = nx.all_neighbors(G, node)
 nnbrs = nx.non_neighbors(G, node)
 (c_1, i_1) = ramsey_R2(G.subgraph(nbrs))
 (c_2, i_2) = ramsey_R2(G.subgraph(nnbrs))
 c_1.add(node)
 i_2.add(node)
 return (max(c_1, c_2, key=len), max(i_1, i_2, key=len))

def ramsey_R2 ( G ) : if ( not G ) : return ( set ( ) , set ( ) ) node = arbitrary_element ( G ) nbrs = nx . all_neighbors ( G , node ) nnbrs = nx . non_neighbors ( G , node ) ( c_1 , i_1 ) = ramsey_R2 ( G . subgraph ( nbrs ) ) ( c_2 , i_2 ) = ramsey_R2 ( G . subgraph ( nnbrs ) ) c_1 . add ( node ) i_2 . add ( node ) return ( max ( c_1 , c_2 , key = len ) , max ( i_1 , i_2 , key = len ) )
approximately computes the ramsey number r for graph .