Sample Input 4 1 10 2 13 4 25 -1 36 -1 -1 3 4 3 2 Sample Output 48 29 23

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

How would I code this in C using trees?

Problem

Given the employee's traversal of the park, and the exhibits that the visitors want to visit determine how
many unique monkeys the visitor will see on their way from the entrance to the exhibit and then back.

Input

Input will begin with a line containing 1 integer, n (1 ≤ n ≤ 200,000), representing the number of exhibitsin the park (including the entrance). The following line contains 2 integers, i and m (i = 1; 1 ≤ m ≤ 5,000), representing the ID of the entrance and the number of monkeys at the entrance. Each of the following 2n - 2 lines will contain a path description recorded by our employee. If this is the first time the employee used the path, then the line will contain two integers, i and m (2 ≤ i ≤ n; 1 ≤ m ≤ 5,000), representing the ID of the destination exhibit and the monkeys at the destination exhibit respectively. If this is the second time the path is used, then the line will contain the integer -1 instead, since the ID and number of monkeys were already recorded. You can assume that the monkeys don’t move between exhibits. The following line contains a single integer, v (1 ≤ v ≤ 500,000), representing the number of visitors to the park. The following v lines will each contain a single integer, e (1 ≤ e ≤ n), representing the ID of the exhibit that the guest is going to visit.

Output

Output should contain v lines. Each line will contain a corresponding integer representing the number of
unique monkeys seen in the corresponding visitor’s park visit. The order of the output should correspond
to the order of the input.

### Sample Input and Output

**Sample Input:**

```
4
1 10
2 13
4 25
-1
3 6
-1
-1
3
4
3
2
```

**Sample Output:**

```
48
29
23
```

#### Explanation:

- The table above shows two columns labeled "Sample Input" and "Sample Output."
- The "Sample Input" column contains a list of numbers structured in pairs, followed by single numbers, and the "Sample Output" column contains a list of three numbers.
- The specific computation or process to derive the "Sample Output" from the "Sample Input" is not explicitly defined in the input data provided.
Transcribed Image Text:### Sample Input and Output **Sample Input:** ``` 4 1 10 2 13 4 25 -1 3 6 -1 -1 3 4 3 2 ``` **Sample Output:** ``` 48 29 23 ``` #### Explanation: - The table above shows two columns labeled "Sample Input" and "Sample Output." - The "Sample Input" column contains a list of numbers structured in pairs, followed by single numbers, and the "Sample Output" column contains a list of three numbers. - The specific computation or process to derive the "Sample Output" from the "Sample Input" is not explicitly defined in the input data provided.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 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