Add parent nodes to ease pattern counting.