Help needed in cses longest flight route

my code link → https://cses.fi/paste/790257604173567924c0d4/
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…
https://cses.fi/paste/bc5d64c2532f469f2333c5/
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.