Tree construction
Practice
3.2 (5 votes)
Graphs
Algorithms
Breadth First search
Problem
79% Success 603 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$$.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
90 votes
Tags:
AlgorithmsApprovedBreadth First SearchDepth First SearchGraphsMediumReady
Points:30
21 votes
Tags:
AlgorithmsBreadth First SearchGraphs
Points:30
10 votes
Tags:
AlgorithmsBreadth First SearchGraphsMedium
Editorial
Login to unlock the editorial