Tom’s Area Tom is a male cat. He doesn’t like when someone enters his area while he is sleeping. Tom has a habit of sleep walking. His master, Neko, wants to enter his room without disturbing and entering Tom’s possible sleeping area. Tom covers a radius of r units. Help Neko in figuring out what all possible areas he cannot enter. Given n, r, and list of edges, find and print the number of different areas Neko cannot enter. The area of path selected cannot be isomorphic. Input: The first line contains two space-separated integers, n and r. Each of the next n-1 lines contains two separated integers a and b (which is a bidirectional edge) with a unit length. Output: Print, a single integer, the total number of areas. Constraints: 1<= n <=3000 0<= r <=3000 1<= x, y <=n Sample Test Case: Sample Input: 7 1 1 5 2 7 1 2 1 3 1 4 2 6 Sample Output: 3 Explanation: In the diagram below, blue nodes denote the possible areas Tom can sleep in: The last 5 areas are considered to be the same (i.e., they all consist of two nodes connected by one edge), so we print 3 as our answer.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Tom’s Area

Tom is a male cat. He doesn’t like when someone enters his area while he is sleeping. Tom has a habit of sleep walking. His master, Neko, wants to enter his room without disturbing and entering Tom’s possible sleeping area. Tom covers a radius of r units. Help Neko in figuring out what all possible areas he cannot enter.

Given n, r, and list of edges, find and print the number of different areas Neko cannot enter. The area of path selected cannot be isomorphic.

Input:

The first line contains two space-separated integers, n and r.

Each of the next n-1 lines contains two separated integers a and b (which is a bidirectional edge) with a unit length.

Output:

Print, a single integer, the total number of areas.

Constraints:

1<= n <=3000

0<= r <=3000

1<= x, y <=n

Sample Test Case:

Sample Input:

7 1

1 5

2 7

1 2

1 3

1 4

2 6

Sample Output:

3

Explanation:

In the diagram below, blue nodes denote the possible areas Tom can sleep in:

The last 5 areas are considered to be the same (i.e., they all consist of two nodes connected by one edge), so we print 3 as our answer.

Original Tree
2
7.
7.
7
2
2
7
Transcribed Image Text:Original Tree 2 7. 7. 7 2 2 7
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY