I tried to solve question using topological sort from the reference https://codeforces.me/contest/1388/submission/88532119 .It passed till test 7 but gave runtime error on test 8 with exit code 1, Here's my code https://ideone.com/MK0Ra6 , please help me correct it.
Thanks in advance ☺️








It's stack overflow due to recursive function
topsort()See this