The Battle of Panipat
Practice
5 (2 votes)
Algorithms
Approved
Graphs
Hard
Open
Problem
46% Success 277 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

This is 1526 A.D. Third Battle of Panipat between Babur and Ibrahim Lodi, the current ruler of India is going on.

Realising that Lodi has much larger army, Babur planned to attack the cities of India to bring the moral of the soldiers of Lodi down.

Now, Lodi had been ordered by his ancestors that, if he is to rule India, the cities in India should be connected and this system should always form a tree.

Now, in 1526, India had N cities(numbered 0 to N-1) all connected by roads and the whole system formed a tree. Lodi had to plan to save his cities. So he decided to use his special power S.H.I.E.L.D. And since all the other cities would be destroyed he wanted the protected cities system should form a tree.

S.H.I.E.L.D was an expensive power and Lodi decided that he would use it only on some specific cities. Now you being the prime minister of the ruler, need to tell him in how many ways he can do this. Lodi may even not use this power at all on any city or he may even select all the cities.

INPUT

First line contains the N: number of cities.

Next N-1 lines contain u and v, denoting a path between city number 'u' and city number 'v'.

OUTPUT

Print the required number of ways modulo 10^9 + 7.

CONSTRAINTS

2 <= N <= 10^5

0 <= u,v < N

Given arrangement will be a tree.

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
AlgorithmsDepth First SearchGraphs
Points:50
1 votes
Tags:
AlgorithmsGraphsHard
Points:50
1 votes
Tags:
AlgorithmsApprovedGraphsHard