Help needed in Graph problem [1020B]

Revision en2, by avdp, 2021-03-15 10:46:04

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).

P.S. I checked that no blog exists on this problem and Please forgive me as I know this may be a NOOB doubt and I have started learning Graphs a week back only.

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)