Question 3 (Group discussion) A lecture hall with n people indexed from 1 to n. Each people either has no mentor or exactly one mentor, who is another person with a different index. A person X is considered as the supervisor of another person Y if at least one of the following is true: (1) Person X is the mentor of person Y. (2) Person Y has a mentor person Z such that person X is the supervisor of person Z. People in hall will not form a cycle, i.e., there will not exist a person who is the supervisor of his own mentor. You need to divide n people in the lecture hall into several groups for discussion as required: (1) each person belongs to exactly one group; (2) Within any group, there must not be two people X and Y such that X is the supervisor of Y. Please tell us the minimum number of groups must be formed. Examples: Input with n+1 lines. The first line contains an integer n (1sns2000), referring to the number of people. Each of the next n lines contains an integer m (1sm;sn or m;=-1). Every m¡ represents the mentor for the ith person. If m; equals to -1, it means that the įth person does not have a mentor. We assume that no person will be the mentor of himself (m; + i). Output the minimal number of the groups that must be formed. Input: 5 -1 1 1 -1 Output: 3 Explanation: There are five persons in total. The (1), (2,4), (3,5) persons can form three groups as required.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Could you make it in C++ language?

 

Question 3 (Group discussion) A lecture hall with n people indexed from 1 to n. Each
people either has no mentor or exactly one mentor, who is another person with a different
index. A person X is considered as the supervisor of another person Y if at least one of the
following is true:
(1) Person X is the mentor of person Y.
(2) Person Y has a mentor person Z such that person X is the supervisor of person Z.
People in hall will not form a cycle, i.e., there will not exist a person who is the supervisor of
his own mentor. You need to divide n people in the lecture hall into several groups for
discussion as required: (1) each person belongs to exactly one group; (2) Within any group,
there must not be two people X and Y such that X is the supervisor of Y. Please tell us the
minimum number of groups must be formed.
Examples:
Input with n+1 lines. The first line contains an integer n (1sns2000), referring to the number of
people. Each of the next n lines contains an integer m (1sm;Sn or m=-1). Every m¡ represents the
mentor for the ith person. If m¡ equals to -1, it means that the ith person does not have a mentor. We
assume that no person will be the mentor of himself (m; ± i).
Output the minimal number of the groups that must be formed.
Input:
-1
1
2
1
-1
Output:
3
Explanation: There are five persons in total. The (1), (2,4), (3,5) persons can form three groups as
required.
Transcribed Image Text:Question 3 (Group discussion) A lecture hall with n people indexed from 1 to n. Each people either has no mentor or exactly one mentor, who is another person with a different index. A person X is considered as the supervisor of another person Y if at least one of the following is true: (1) Person X is the mentor of person Y. (2) Person Y has a mentor person Z such that person X is the supervisor of person Z. People in hall will not form a cycle, i.e., there will not exist a person who is the supervisor of his own mentor. You need to divide n people in the lecture hall into several groups for discussion as required: (1) each person belongs to exactly one group; (2) Within any group, there must not be two people X and Y such that X is the supervisor of Y. Please tell us the minimum number of groups must be formed. Examples: Input with n+1 lines. The first line contains an integer n (1sns2000), referring to the number of people. Each of the next n lines contains an integer m (1sm;Sn or m=-1). Every m¡ represents the mentor for the ith person. If m¡ equals to -1, it means that the ith person does not have a mentor. We assume that no person will be the mentor of himself (m; ± i). Output the minimal number of the groups that must be formed. Input: -1 1 2 1 -1 Output: 3 Explanation: There are five persons in total. The (1), (2,4), (3,5) persons can form three groups as required.
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education