<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
Step1:  Step 1
Step2:  2. Flatten tree
Step3:  3. Use regexp path queries over tree!
<ASSISTANT_TASK:>
Python Code:
def root_tree_at(new_root):
    
    Given a node, remove all parents and add as children
    so that this node becomes the new root
    
    # Check to see if the new root has any parents...
    parents = new_root.xpath("..")
    if len(parents) > 0:
        p = root_tree_at(parents[0])
        p.remove(new_root)
        new_root.append(p)
    return new_root
root = root_tree_at(root.xpath("//*[@cid='P1'][1]")[0])
t = XMLTree(root)
t.render_tree()
Explanation: Step 1: Reconfiguring the tree for flattening
We think if we reconfigure the tree so that one of the two candidates is the root, things will be much easier...
End of explanation
def flat_tree(root):
    if root.get('dep_label') is not None:
        s = '--%s--> %s' % (root.get('dep_label'), root.get('word'))
    else:
        s = root.get('word')
    if len(root) > 0:
        s += ' ( %s )' % ', '.join(filter(lambda x : x is not None, [flat_tree(c) for c in root]))
    return s
ft = flat_tree(t.root)
print ft
Explanation: 2. Flatten tree
End of explanation
re.search(r'[G](\s*--\w+-->\s*){0,5}[P]', ft)
Explanation: 3. Use regexp path queries over tree!
End of explanation
<END_TASK>