Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя nqs_1

Автор nqs_1, история, 5 лет назад, По-английски

how to mark all the nodes that are in a cycle in a graph?

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

You can use degree of nodes like doing BFS. The detail is in this post

»
5 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I assume that you are dealing with directed graphs. How about finding strongly connected components? Clearly, any cycle must be in some SCC and the nodes in a SCC (with more than 1 node) are in a cycle by definition of a strongly connected component. So, you can just dump those SCCs with one node only. And mark the nodes in the rest of the SCCS.

»
5 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Find all bridges in the graph, a vertex is in a cycle iff atleast one of the adjacent edge is not a bridge.