One at a time.

If there is a child-parent-grandparent relationship, then the parent and grandparent will be added to the $sites array. If one child has two parents, only one will be added (see line 70)