Maximum GCD Subset
You are given a rooted tree with $N$ nodes (numbered $1$ through $N$). Node $1$ is the root. You are also given integer sequences $x_1, x_2, \ldots, x_N$ and $v_1, v_2, \ldots, v_N$. Let $S$ be a subset of nodes. It is called *valid* if it is non-empty and the following conditions hold: - There is no pair of nodes $(i, j)$ such that $i,j \in S$ and $i$ is an ancestor of $j$. - The greatest co
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.
Sign in to chat with the tutor and save your progress.
Sign in to start