SP17755 TREEPAL - Tree and Palindrome

Description

**Tree and Palindrome | TREEPAL** You are given a tree with **N** nodes. The tree has following properties 1. It is rooted at node 1 2. Node 1 situated in level 0. The children of node 1 is situated in level 1 , the children of the level 1 nodes is situated in level 2 , the children of the level 2 nodes is situated in level 3 and so on ….... . 3. Every node is marked by an alphabet. The nodes of the same level are marked by the same alphabet. 4. Level zero nodes are marked by 'a' , level 1 nodes are marked by 'b' , level 2 nodes are marked by 'c' …... level 25 nodes are marked by 'z', level 26 nodes are marked again by 'a', level 27 nodes are marked by 'b' and so on … (the leveling is rotational). 6. If we take all the alphabets of the nodes serially which are in the path from node a to node b (including a, b) and concatenate them, then we find a string. The name of the string is **Bokkor** string of pair (a, b). You will be given a pair of distinct nodes. You don't know in advance which pair will be given. The probability of choosing every pair is same. Now your job is to calculate the probability that the **Bokkor** string of the given pair is a palindrome in **p/q** format (where p and q are co-prime). ![Tree Structure](http://dl.dropboxusercontent.com/u/34972503/SM.png) Figure: Tree Structure Here the pair (2, 3) forms the Bokkor string “bab” which is a palindrome. And the pair (4, 5) forms the Bokkor string “cbabc” which is also a palindrome. There are no other palindromic Bokkor pairs. ![Equation](http://dl.dropboxusercontent.com/u/34972503/sm2.JPG) Total numbers of Bokkor pairs 2 1

Input Format

N/A

Output Format

N/A