joseph_goldberg's blog

By joseph_goldberg, 3 years ago, In English

Can someone please help me in understanding part of the code? Submission 34448654 Problem 916E - Jamie and Tree

Author of the code William Lin

Part of the code I don't understand I think it is something related to storing the ancestors on different levels but I can't understand properly any help will be great.

for(int i=1; i<=lg2(n); ++i)
		for(int j=0; j<n; ++j)
			anct[i][j]=anct[i-1][j]==-1?-1:anct[i-1][anct[i-1][j]];

I have seen other solutions they did the same thing but I couldn't understand.

Update: I understood from Errichto Channel Link

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

»
3 years ago, # |
  Vote: I like it +22 Vote: I do not like it

It's binary lifting. You can learn it here: Click