AlgoUniversity
  • Go Back
Discussion
Minimum Camera Required :

Author

Ujjwal Srivastava

Difficulty Level : Medium

Submissions : 290

Asked In : Factset

Marks :30

: 13 | : 0

Given a binary tree rooted at $$$1$$$, you need to place cameras on some nodes such that every node in the tree could be under surveillance.

Given that each camera will provide surveillance to an immediate neighbor in the tree.

You need to find the minimum number of nodes such that the total number of cameras to be installed is minimum.

Input

The first line contains an integer $$$n$$$, the number of nodes in the tree. The next $$$n$$$ lines contain two space-separated integers $$$x$$$ and $$$y$$$ denoting an edge between $$$x$$$ and $$$y$$$.$$$(1 \le n \le 10^3).$$$ It is guaranteed that the tree is a binary tree.

Output

Output minimum number of nodes on which cameras should be installed such that the total number of cameras to be installed is minimum.

Examples

Input
5
1 2
1 5
2 3
3 4
Output
2
Input
3
1 2
1 3
Output
1
Input
4
1 2
2 3
3 4
Output
2
Input
11
1 2
2 3
2 4
3 5
3 6
4 7
4 8
1 9
9 10
9 11
Output
3

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.