Join Regular Classroom : Visit ClassroomTech

Backbenchers | Coding Questions | Codewindow.in

It is examination time and as always, the backbenchers are finding ways to cheat in the exam and they need your help. Their teacher is very fond of data structures and has mad the seating arrangment in the form of a tree. There are N students in class numbered from 1,2….N with 1 as the root of this tree.We have k first benchers(teachers favorites) students in the class. The backbenchers are planning to pass chits in teams,but are afraid of the first benchers.If any chit reaches them. They will complain to the teacher.

A cheat way is defined as the path along which a chit can be passed without going through a first bencher. Given the seating arrangement and numbers of first benchers, Your task is to find the longest cheat way possible.

Input Specification:
Input 1: Total number of students in the class N. (1<=N<=10000).
Input 2: A 2D array with N-1 rows, each consisting of two integers C and D, Denoting C and D are sitting adjacent. Only adjacent students can pass chits directly to each other.
Input 3: Number of first benchers. (0<=k<=N)
Input 4: Array of K numbers denoting position of each first bencher. (1<=input4[i]<=N)

Output Specifications:
Return length of the longest cheat way possible.

Example 1
Input 1: 5
Input 2: {{1,2},{1,3}{3,4},{3,5}}
Input 3: 1
Input 4: {3}

Output:
1

Also Checkout

Recent Posts
Categories
Pages