King's Palace
면접 대비시간 제한6초메모리 제한1024 MB
N개의 벽을 3가지 색으로 칠할 때, 주어진 금지된 색 조합을 모두 피하는 경우의 수를 구한다. N은 최대 22이다.
문제
There are walls in the hall of the King's palace, numbered by integers from to . The King asks the Royal Painter to paint each wall in one of three colors (red, green, or blue). Additionally, the King gives orders.
Every order has the following form: given two walls, and , and two colors, and , the order dictates that, if the wall is painted with color and the wall is painted with color , the Royal Painter has to be executed.
Your task is to find a number of ways to paint the walls so that the Royal Painter will not be executed.
입력
The first line of the input contains two integers and (, ): the number of walls and the number of orders, respectively.
Each of the following lines describes one King's order and contains an integer , a letter , an integer , and a letter , separated by single spaces (, and are letters from 'R', 'G', and 'B', denoting the red, green, and blue colors, respectively). You may assume that all orders are pairwise distinct (no two orders have the exact same effect).
출력
Print one integer: the number of ways to paint the walls so that the Royal Painter will not be executed.