I am unable to get what is wrong with my logic. The question link is here: http://codeforces.com/contest/580/problem/C

My solution is this: https://pastebin.com/DNgpJGnW

# | User | Rating |
---|---|---|

1 | MiFaFaOvO | 3681 |

2 | Um_nik | 3544 |

3 | maroonrk | 3431 |

4 | tourist | 3409 |

5 | apiadu | 3397 |

6 | 300iq | 3317 |

7 | ecnerwala | 3260 |

7 | Benq | 3260 |

9 | LHiC | 3229 |

10 | TLE | 3223 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 194 |

2 | antontrygubO_o | 191 |

3 | vovuh | 178 |

4 | pikmike | 176 |

5 | tourist | 166 |

6 | Um_nik | 165 |

7 | McDic | 164 |

8 | ko_osaga | 163 |

9 | Radewoosh | 162 |

10 | 300iq | 156 |

I am unable to get what is wrong with my logic. The question link is here: http://codeforces.com/contest/580/problem/C

My solution is this: https://pastebin.com/DNgpJGnW

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/29/2020 01:07:44 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Your code gives WA as it does not stop on the path to one of the leaf nodes even after having greater than m consecutive vertices with cats,it refreshes the value of variable val to 0 on the same path and counts those leaf nodes as well.Example test case would be:

Input :

4 1

1 1 0 0

1 2

2 3

3 4

Output :

0 (but your code gives output as 1)

You can use a return statement to return from the path where greater than m consecutive vertices have cats.

Here is a link to my submission:39347359

you are right! thanks a lot.

Hey I couldn't understand why the answer is 2 in the second example shown in that problem.

The way I see it he can only go restaurant at vertex 5 through the path 1 -> 2 -> 5 which has only 1 cat. The path to 4, 6, 7 have 2 cats which exceeds the threshold.

Here is my code — https://pastebin.com/ws0frPRy

Thanks for your time !

Best Regards, Srivatsa

The question asks for consecutive vertices so the path to 4 is fine since the vertices with cats are not next to each other on the path.

Thanks, I missed that part. Now it makes sense. I will try to update my logic.

i am unable to understand why my logic is incorrect here is my code https://pastebin.com/XeECnx5W