Question: You are about to join a Guild. There are N potions in this guild, each with specific brewing requirements. You have been given a REQUIREMENTS

You are about to join a Guild. There are N potions in this guild, each
with specific brewing requirements. You have been given a REQUIREMENTS list of size M,where REQUIREMENTS[i] consists of [Pi,Qi] indicating that potion Pi must be brewed before potion Qi can be concocted. In one brewing cycle, you can prepare at most K potions. Thus, you need to determine the minimum number of brewing cycles required to successfully concoct all potions.
Note: It is guaranteed that there is a feasible sequence to concoct all the potions. The most optimal solution is not required.
Format :
The first line of each test case contains three single space-separated integers N,M and K represent the number of potions, number of repuirements, and maximum potions that you can brew in one brewing cycle respectively.
The next M line of each test case contains two single space-separated integers P and Q representing that the potion P must be concocted before the potion Q.
Constraints:
1<= N <=150<= M <= N (N 1)/2
1<= Q, P and K <= N
Input :
432
21
31
14
Output :
3
Input :
542
21
31
41
15
Output :
4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!