Codechef Internship Test

I TRIED LCA BUT IT GOT TLE ONLY 40 PERCENT SUBTASK PASSED HOW U PREPROCESS THE LCA

Nah, straight forward binary lifting

2 Likes

I was also getting partial, but then I saw FASTIO is recommended as input can be large, so after using FASTIO, I got full points.

I solved all, but very late, didn’t know binary lifting.

2 Likes

which advanced algorithm :thinking: ?

Can you briefly describe it? What you did?
I know binary lifting.

Oh I see

just calculate sum from node root to x
now for a query the answer will be (sum(u)+sum(v)-2*sum(lca(u,v))
lca should be computed in LOGN otherwise you will get TLE (binary lifting part )

1 Like

Yup I also did it by LCA with sparse table

how did you solve last problem , i tried half of diameter , but giving wa

ohh it was straightforward problem. idk what i was thinking. :frowning:

Ceil of half diameter.

Sure, so for each node assign the weight of it’s parent edge to it. And then precompute for the sum of all assigned values of nodes in the path from root to every node. Now for any 2 nodes. We can calculate the answer as ->
a[i]= weight of the edge connecting node i and it’s parent
S_i= Set of all nodes in the shortest path from root to i_{th} node
p[i] =\sum_{j \in S_i}a[j]
for any u,v ,
ans_{u,v}=p[u]+p[v]-2*p[lca(u,v)]

1 Like

yaa , did the same , but didn’t work

1 Like

Yes, it was well known problem. Thank you :slight_smile:

Can you please post your solution. I did the same thing but I still got wrong answer.

I guess you may have got WA due to int as i got he same.Converting weights array to long long worked for me.

anyone know about selection criteria for coding round of last year ?

2 Likes

will the ranklist made public?

orz