#K10486. Minimum Weeks to Complete Training Module

    ID: 23257 Type: Default 1000ms 256MiB

Minimum Weeks to Complete Training Module

Minimum Weeks to Complete Training Module

You are given a set of training modules numbered from 1 to n. Each module may have several prerequisite modules that must be completed before it can be taken. In each week, you can complete any modules that have all their prerequisites satisfied. Given the prerequisite information for each module, determine the minimum number of weeks required to complete a specific target module t.

Input Format:
The first line of input contains two integers n and t, where n is the number of modules and t is the target module index.
This is followed by n lines. The i-th line begins with an integer k, representing the number of prerequisites for module i, followed by k space-separated integers denoting the prerequisite module indices.

Note: It is guaranteed that the modules can be completed in some order.

inputFormat

The input is read from standard input. The first line contains two integers n and t. The following n lines each describe a module: each line begins with an integer k (the number of prerequisites for that module) followed by k space-separated integers indicating the indices of the prerequisite modules.

outputFormat

Output a single integer to standard output, representing the minimum number of weeks required to complete module t.## sample

4 3
0
1 1
1 2
2 2 3
3

</p>