Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the ways to paint a tree?

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.

like image 717
newbie Avatar asked Sep 20 '16 10:09

newbie


People also ask

What paint to use on trees?

Use only white latex paint, preferably interior grades. While exterior latex may be used, it may present a greater chance of tree damage. Oil base paints should never be used, as they are toxic to the trunk. 3.


Video Answer


1 Answers

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).

like image 122
Dave Avatar answered Sep 25 '22 22:09

Dave