← All problemsSign in

Tree Requirements (Hard)

CodeChefRating 3218Open on judge ↗

**This is the hard version of the problem. The only difference between this and easy version is the constraints on $N$ and $M$ — notably, in this version, $N, M \leq 2\cdot 10^5$.** You are given a tree with $N$ nodes. Each node $i$ has an associated value $A_i$. You can choose some subset $S$ of the $N$ nodes. You are given $M$ requirements that $S$ should satisfy, each of the form: - $(u, r, k

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start