Tree construction
Practice
3.2 (5 votes)
Graphs
Algorithms
Breadth First search
Problem
79% Success 588 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You are given a tree consisting of $$n$$ nodes.
You can select any number of nodes from the tree that you want to save. The remaining nodes will be destroyed but the saved nodes again form a tree.
Find the total number of such ways to form the tree.
Note: You may not select any node or you may save all nodes.
Input format
- The first line contains a single integer $$N$$ ( 2 ≤ $$N$$ ≤ $$10^5$$) denoting the number of nodes in the tree.
- Next $$N-1$$ lines contain two integers, $$u$$ and $$v$$, denoting an edge from node $$u$$ to node $$v$$ ($$0 \le u,v < N$$).
Output format
Print the required number of ways modulo $$10^9 + 7$$.
Submissions
Please login to view your submissions
Similar Problems
Points:30
25 votes
Tags:
AlgorithmsApprovedBreadth First SearchGraphsMediumOpenRecursion
Points:30
8 votes
Tags:
GraphsAlgorithmsBreadth-first search
Points:30
24 votes
Tags:
ApprovedBreadth First SearchDepth First SearchGraphsMediumOpen
Editorial