← All problemsSign in

Trees Are Fun

CodeChefRating 3060Open on judge ↗

You are given a rooted tree consisting of $N$ nodes numbered from $1$ to $N$, where the $i^{th}$ node has color $C_i$. The root of the tree is node $1$. Let $F_i$ denote the frequency of color $i$ in the tree, and, $S_u$ denote the set of colors of all vertices in the subtree of node $u$. For each node $u$ $(1\le u \le N)$, find $\prod_{i \in S_1 \setminus S_u} F_i$. In other words, for e

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