← All problemsSign in

Tree Greatness

Given a tree consisting exactly of n vertices and rooted at vertex 1. Tree is a connected undirected graph with n−1 edges. Each vertex *v* of this tree has a value $a_{v}$ assigned to it. The greatness of a vertex i = (value[i] x 1) + (value[par[i]] x 2) + (value[par[par[i]] x 3) + (value[par[par[par[i]]] x 4) + ... until you reach the root i.e par[par[.....par[i]...]] is the root where par[i]

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