It seems for each subtree,the optimal moves is aaaaaaababababa or bbbbbbbbabababab (i.e. alice makes x consecutive moves then bob and alice make alternative moves or bob makes y consecutive moves then alice and bob make alternative moves)(I'm not clear, but seems correct). If this conclusion is correct,we can compute sg[id][con_moves] using dynamic programing for each con_moves we can divide them to x moves to left subtree,y moves to right subtree(x+y==con_moves)