real time counter; and building tree from child-parent pairs