给定 n 作为节点数和边作为边列表
谁能告诉我我的代码有什么问题。它适用于某些实例,但不适用于所有实例
for edgeindex in range(len(edges)):
alltrue = [True]*(n)
visited = [False]*(n)
S = []
start = edges[edgeindex][1]
visited[start] = True
S.append(start)
nex = start
for edgeindex2 in edges[edgeindex:]:
if edgeindex2[0] != nex:
continue
if visited[edgeindex2[1]] == False:
visited[edgeindex2[1]] = True
S.append(edgeindex2[1])
nex = edgeindex2[1]
if visited == alltrue:
return 'yes'
return 'no'