PiasRoY's blog

By PiasRoY, history, 4 years ago, In English

Update: The problem was in my 'decompose' function. Its return type was 'int' though I didn't return anything, so I changed it into 'void' and I got AC. Weird but worked.

I tried to solve this problem using HLD and Segment Tree. I didn't find LCA explicitly rather used HLD.

Code: https://pastebin.ubuntu.com/p/BfxMZH9hz3/

This solution gives runtime error. I can't find any reason for this kind of verdict.

I have already read this blog but couldn't understand why my code isn't working.

Can anyone help me?

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You are asking what's wrong with your code? You should be asking what's wrong with yourself first. Fancy posting a wall of unreadable code without any explanation at all. I don't think anyone's gonna help you to debug.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    nik7 I thought someone from their previous experience may give any hint/testcase that will help me to understand RTE. I never asked anyone to read my code, though I should have explained/comment it (Sorry for that). But even if I did, you with your big ego won't be able to understand it.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Your HLD query is wrong, you may have that head[b] is a parent of lca(a, b) node. it would be better if you could find lca correctly.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Bashca I run that query when both nodes are in different chains. Can you give any testcase?