Jan's coloring book
Time limit1sMemory limit64 MB
Count proper colorings of one of eight fixed maps using at most three of K colors with adjacent areas different.
- Level
Medium7 of 10
- Topics
- Graph, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
Jan liked coloring as a child. He is now a student of electrical engineering, and he bought a coloring book and distinct colors so he can color again.
Jan does not like busy pictures, so he colors each picture with at most three different colors. He never gives the same color to two adjacent areas. If two areas share a line, he says there is no point in drawing that line and then painting both sides the same.
Two areas are adjacent when their boundaries share at least one point. In picture 3 below, areas and are adjacent, and areas and are not.
Before he starts, Jan wants the number of valid ways to color the chosen picture. Two colorings differ when at least one area has a different color.
The eight pictures are the maps below. Each vertex is an area that must be colored. Each edge joins two areas that share a boundary point. Eyes, antennae, and gray fill are not areas and are not colored.
Input
The first and only line contains two integers and (, ): the index of the picture in the book and the number of colors Jan may use.
Output
Print one integer: the number of ways Jan can color picture using the colors, with at most three colors appearing on the picture and with adjacent areas colored differently.
Pictures
Picture 1. Caterpillar. The body is a path of disks. Only consecutive disks are adjacent. The eyes and the antennae are not areas.
Picture 2. A sea cottage. The dual graph has vertices: is the wall, is the door, and are the two panes of the left window, and are the two panes of the right window, is the roof, and is the attic window. The edges are , , , , , , , , .
Picture 3. A well known logo. Inner disk and inner oval do not touch each other. Both sit in white interior . Outer frame touches only the white interior. The edges are , , .
Picture 4. Frosty the Snowman. The dual graph is a tree on vertices. The spine is . Vertex is also adjacent to and , vertex is also adjacent to , , and , and vertex is also adjacent to , , , and .
Picture 5. An abstract ball. Concentric rings, with a horizontal cut through the inner disk and the outer ring but not through the middle ring. Vertices: inner top , inner bottom , middle ring , outer top , outer bottom . Edges: , , , , , .
Picture 6. Pyramid. There are rows of bricks. Row has bricks (). Consecutive bricks in a row are adjacent. The -th brick in row (from the left) rests on bricks and of row , and is adjacent to both.
Picture 7. Daisy. The dual graph is the same as picture 2.
Picture 8. Trampoline. The gray disk is not an area. The white rim is a -cycle: sectors around the disk, with only consecutive sectors adjacent.