Help needed in cses longest flight route

my code link →
i have read on same query raised by @ssrivastava990 . but i am unable to find the solution to make my solution AC .
i have used Dijkstra with weight -1 and was trying to find sssp.
also in some cases when i am print dist[n] instead of size of its path some testcase are giving wrong ans.

Use Simple topological sort…
if it helps:)

i know topological sort can be helpful to solve this question but why my code is wrong i want to know that.