How to calculate the ways to paint a tree's nodes with m colors so that the ends of each edge have different colors?
Any polynomial solution is welcome.
How to calculate the ways to paint a tree's nodes with m colors so that the ends of each edge have different colors?
Any polynomial solution is welcome.
You have m choices for the root. If you paint going down from the root, you have m-1 choices for each additional node. If the number of nodes is n, then the number of ways to paint the tree is m * (m-1)^(n-1).
n=1
and m=1
in the given formula and you will get the correct answer as I mentioned in the comment to your answer. –
Venereal © 2022 - 2024 — McMap. All rights reserved.
O(1)
formula (assuming you don't have to count nodes first): en.wikipedia.org/wiki/Chromatic_polynomial#Examples – Thelmathem