Problem E
Hackenbush Purplehearts
Languages
en
is

Hackenbush is a game played on edges of three colours which all connect to each other or the ground. The edges are all red, green or blue. The first player can hack red and green edges and the second blue and green edges. When a player hacks an edge it is deleted. Any edges that can’t reach the ground are discarded.
The value of a Hackenbush game with red and blue edges can
be defined in a few steps. We say that a blue edge is
You are given a position of Hackenbush Purpleheart. This is a position in the game Hackenbush where all edges are red or blue and there are no cycles.
You need to determine the value of the game. It can be shown that this is always an integer fraction.
Input
The first line contains a single integer
Output
If the value of the game is
Sample Input 1 | Sample Output 1 |
---|---|
12 -1 1 2 3 3 5 5 7 -1 -1 10 10 BRBBRBBRRBRR |
5/2^6 |
Sample Input 2 | Sample Output 2 |
---|---|
39 -1 1 2 3 4 4 4 7 7 9 9 1 12 13 13 15 16 16 18 18 15 21 21 12 24 25 25 24 28 28 24 31 12 33 34 34 2 37 37 BRRRBBRRBBRRRBBRRBRRBBBRBRRBRRBRRBRRRBR |
65/2^12 |