You are given a tree with

nodes.
The tree's nodes are numbered

through

and its edges are numbered

through

.
Each edge is associated with a distance.
There are

lightbulbs, numbered from

to

. For each lightbulb

you are given an integer

- the node number where the lightbulb is, and no two lightbulbs in the same node. Each lightbulb can either be ON or OFF. Each input case will contain the initial state.
You're starting from node

, and need to turn off all lightbulbs. And we can guarantee that there is no lightbulb at the starting point

, and there is no more than one lightbulb in one node.
You can repeat the following operation until all lightbulbs are OFF:
If you are currently located in node

, you will randomly select a new node

with equal probability from {v:

,

should have no lightbulb if

has a lightbulb}. Then you will move to node

by the shortest path and flip (ON

OFF, OFF

ON) the lightbulb in

if node

has lightbulb.
Your task is to compute the expected total distance to light down all lightbulbs.