← All problemsSign in

Tree Coloring

CodeChefRating 1898Open on judge ↗

Given a [tree](https://en.wikipedia.org/wiki/Tree_(data_structure)) containing $N$ nodes. Each node can be coloured using exactly one of the $C$ colours. Find the number of colourings of the tree such that: - All nodes in a path of length at most **two** have **distinct** colours. As the answer can be huge, print it modulo $(10 ^ 9 + 7)$. Note: - Two colourings of a tree are different if there

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