Help needed in Graph problem [1020B]

Revision en1, by avdp, 2021-03-15 10:44:22

1020B - Badge

Guys can Someone give me O(N) approach for this problem as When I checked around 20-30 solutions all were O(N^2) so I need a code basically as I have some idea that If a node is in cycle then the answer is the node itself and else the answer is nearest node in a cycle.

Please help me implement code for O(N).

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English avdp 2021-03-15 10:46:04 169
en1 English avdp 2021-03-15 10:44:22 374 Initial revision (published)