Minwook entered the computer science department of Z University this year, and he wants to take every major course the department offers before he graduates. Some courses have prerequisites: he can take such a course only after he has completed all of its prerequisites. Minwook refuses to give up on engineering accreditation, so he must respect every prerequisite. He wants to know when he can take each major course while respecting them. To keep the calculation simple he settled on these rules.
- There is no limit on how many courses he takes in one semester.
- Every course is offered every semester.
Write a program that computes, for every course, the smallest number of semesters needed to complete it.