Output #1
499122179
595552585
760296751
In the first test case, the algorithm may operate as follows:
* Initially, $D=(-1,-1,-1)$ and $Q=((1,0))$. Remove the first element $(1,0)$ from $Q$.
* $D_1 = -1$, so set $D_1 := 0$. The vertices $x$ adjacent to vertex $1$ such that $D_x= -1$ are $2$ and $3$.
* Add $(2,1)$ to the front of $Q$. Add $(3,1)$ to the end of $Q$. Now $Q=((2,1),(3,1))$.
* Remove the first element $(2,1)$ from $Q$.
* $D_2 = -1$, so set $D_2 := 1$. The vertex $x$ adjacent to vertex $2$ such that $D_x= -1$ is $3$.
* Add $(3,2)$ to the front of $Q$. Now $Q=((3,2),(3,1))$.
* Remove the first element $(3,2)$ from $Q$.
* $D_3 = -1$, so set $D_3 := 2$. There are no vertices $x$ adjacent to vertex $3$ such that $D_x= -1$, so do nothing.
* Remove the first element $(3,1)$ from $Q$.
* $D_3 =2$, so do nothing.
* $Q$ is now empty, so the process ends.
In this case, the final sequence obtained is $D=(0,1,2)$. The probability that the algorithm operates as described above is $\frac{1}{8}$, and the expected sum of the elements of $D$ is $\frac{5}{2}$.