[Solved]Help needed in Profitable Paths(PRT) problem Jan Cook-Off

I’m constantly getting RUNTIME ERROR(SIGSEGV) but I can’t figure out why?
Any help will be highly appreciated.

Below is the link of my submission.
Submission Link

for n==2 you didn’t read the corresponding edge leading to wrong input for subsequent cases

Thanks a lot. I can sleep peacefully now :sweat_smile:

i m also getting WA? will u pls tell me what i m missing >>

my submission link : https://www.codechef.com/viewsolution/29091987
Thanks in advance !

You are storing values in dp[] array after doing the modulo operation which is leading to wrong answers. Actually after doing (dp[i] %= mod) some of the higher values of dp[i] become lower.
E.g.:- If for some ‘i’, (dp[i] = mod+1), and for some ‘j’, (dp[j] = mod-1), then your code is assigning the bigger value of array “a” to ‘j’ and not to ‘i’ as after modulo operation dp[i] = 1, and dp[j] = mod-1 which is leading to wrong answer.

You need to apply the modulo operation only when calculating answers, and not when calculating the contribution of each node.

1 Like