Weighted tree with maximum distance query problem

Revision en1, by nai0610, 2025-03-06 16:15:48

Hello everyone, I have been stuck on this problem for a while, can anyone please give me an idea to solve this problem?

The statement: Given a tree of $$$n$$$ nodes and weighted edges (numbered from $$$1$$$ to $$$n-1$$$) and $$$q$$$ queries of 2 types:

Type 1: gives $$$k$$$ distinct nodes $$$u_1,u_2,...,u_k$$$ and a node $$$v$$$ different from the given nodes and asks for the maximum sum of edge weights of a path coming from node $$$v$$$ to another node that doesn't go through any of the node $$$u_1,u_2,...u_k$$$.

Type 2: updates the weight of the $$$i^{th}$$$ edge to $$$w$$$.

$$$n,q\leq 2\cdot 10^5,w\leq 10^9$$$, the sum of $$$k$$$ of all queries doesnt exceed $$$2\cdot 10^5$$$.

original statement (in Vietnamese): https://lqdoj.edu.vn/problem/lqdojcontest15bai5

I've tried constructing virtual trees for each type 1 query but couldn't handle the nodes not included in the query, also tried using centroid decomposition, each node on the centroid tree storing a segment tree for Euler tour but couldn't do the edge updates efficiently.

Thank you for your attention.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English nai0610 2025-03-06 16:15:48 1089 Initial revision (published)