Siddharth and Permutations Graphs

my code link click
i cannot find the mistake plese help
my logic:
given case is
6
2 -1 1 5 -1 4

  • i consider graph with edges like 3->1, 1->2, then 6->4 and 4->5

  • now i do a dfs from vertex with indegree 0 gradually e.g. from 3 here first and then from 6

  • but as soon as i get a vertex with -1 i stop

  • so, they get marked
    3 gets 1 1 gets 2
    6 gets 3 4 gets 4

  • then after this i number vertices with -1 in decreasing order i.e.
    5 gets 5 2 gets 6

You will understand better , refer this -:
See tutorial
https://codeforces.com/problemset/problem/798/E

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.