How to solve Path Queries CFS2004

I thought about Euler tours by which i can find the F function for a node in O(1) but couldn’t think of anything after. I’m surprised this has more solves than CFS2003 or am I missing something obvious?

Can anyone help?

precompute answer for all nodes … use prefix sum to find the answer of a particular node… then use LCA to answer queries

1 Like