![]() | 1 | initial version |
Unless there is a better idea, one can iterate over all cycles in the graph as explained at https://ask.sagemath.org/question/69318/find-all-cycles-in-an-undirected-graph/ and keep track what vertices are visited by cycles of what length.