Graph: . You need to find the answer for each node. The answer is the total path length until returning to a cycle. Start DFS at : path , next is (in path). Cycle detected with length . Assign to nodes , , .
All cycle nodes get the cycle length as their answer. Start DFS at : path , next is (already processed with answer ). Node has answer . Node is step from the cycle, so answer is . Tail nodes add their distance.