adapt get_ancestors example in tree docs