You are given a tree with N nodes, labeled with distinct integers from 1 to N. You are also given M node pairs of the tree, (a1,b1),(a2,b2),…,(aM,bM).
Direct every edge of the tree so that for each given pair (ai,bi) there is a path from ai to bi, or a path from bi to ai. Count the ways to do this. The count can be very large, so print it modulo 109+7.
A tree is a graph with N nodes and N−1 edges in which every node has a path to every other node.