One New Zealand Interview Question

question related to graph algorithm