Блог пользователя Yath

Автор Yath, история, 20 месяцев назад, По-английски

My code is giving runtime error for all the cases that have n=1e5 and m = 2e5 input — Test cases 6 , 7 , 8 and 9 on the CSES website. Here is the submission: https://onlinegdb.com/ciDQleE8W

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
20 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

For this input

Input
Graph

your code finds the circle (2,4,3) twice and ends up setting v = 3 and parent[3] = 1. Which is not the parent you want. Now the while loop will never stop, which causes ans to get larger and larger until it is too large and you get runtime error.