defEnumerateSubgraphs(G,k): N =len(G) visited = [False] * N queue = [] ans =0 sub ={} sub_graph ={}for i inrange(N): queue.append([i])while queue: front = queue[0] queue = queue[1:]iflen(front)==k: degree = [0] * Nfor f in front:for j in front:if G[f][j]==1: degree[f]+=1 degree[j]+=1iflen(set(front))!=len(front):continueifstr(sorted(front))in sub_graph:continue sub_graph[str(sorted(front))]=1ifstr(sorted(degree))in sub: sub[str(sorted(degree))]+=1else: sub[str(sorted(degree))]=1print(front)continuefor i inrange(N):if G[front[-1]][i]==1and i > front[0]: queue.append(front+[i])for s in sub: ans += sub[s]return ansG_adj = [[0,0,1,0,0],[0,0,1,0,0],[1,1,0,1,1],[0,0,1,0,1],[0,0,1,1,0]]print("Start!")ans =EnumerateSubgraphs(G_adj, k=5)print(ans)