← All problemsSign in

Ayvanat and Ugly Tree

Problem statement Tidu is very pr0, but he has one weakness: Trees (maybe because trees are big and he's a smoll boi) Formally, a tree is defined as a collection of N connected nodes with N-1 edges where there is only one path from a node u, to another node v. One day a friend of Tidu's, Ayvanat, had an ugly tree of N nodes. The tree was ugly because the sum of values of nodes in the tree was n

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