Skip to content

Commit ced3d30

Browse files
authored
Update shortest-cycle-in-a-graph.py
1 parent 27b5d33 commit ced3d30

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Python/shortest-cycle-in-a-graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def bfs(u):
2222
if dist[v] != INF:
2323
assert(abs(dist[v]-dist[u]) <= 1)
2424
if dist[v] != dist[u]-1:
25-
result = min(result, 1+dist[u]+dist[v])
25+
result = min(result, 1+dist[u]+dist[v]) # d = dist[u]+1 >= 2, check if any cycle of length 2*d-1 or 2*d exists
2626
continue
2727
dist[v] = dist[u]+1
2828
new_q.append(v)
29-
if result != INF:
29+
if result != INF: # a cycle of length 2*d-1 or 2*d was found, early return
3030
break
3131
q = new_q
3232
return result

0 commit comments

Comments
 (0)