← All problemsSign in

Beautiful Branch

CodeChefRating 3546Open on judge ↗

**This is an interactive task.** You are given a tree with $N$ nodes. Chef has secretly marked two nodes $A$ and $B$ as *special*. Let the shortest path between nodes $A$ and $B$ be denoted as the *beautiful branch*. Note that nodes $A$ and $B$ can be **equal**, in which case, *beautiful branch* consists of only one node. We define $D(X)$ as the **minimum** possible distance of node $X$ from

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