#P4589. [TJOI2018] 智力竞赛

[TJOI2018] 智力竞赛

Description

Xiaodou signed up for an intelligence contest. He brought nn good friends as his cheering group to take part in the contest together. The rules are as follows.

There are mm problems in total. Each person has 11 chance to answer questions. In each attempt, they choose one problem to answer. After answering correctly, they may continue to answer the subsequent problems of this problem, until they answer a problem incorrectly or there is no subsequent problem.

Each problem has a value. At the end of the contest, the reward value that a participant gets is equal to the minimum value among the problems that were not answered by this participant and his cheering group.

Now we know that Xiaodou and his cheering group are very strong and can solve all the problems in this contest.

Xiaodou wants to know, given the information about the problems and their subsequent problems, what is the maximum value he can obtain.

Input Format

The first line contains two integers n,mn,m. (n50,m500n\leq50,m\leq500).

The next mm lines describe the problems. Line i+1i+1 gives the information of problem ii, in the form vi,ki,ai,1,ai,2,...,ai,kiv_i,k_i,a_{i,1},a_{i,2},...,a_{i,k_i}, where viv_i is the value of this problem, kik_i is the number of subsequent problems of this problem, and ai,1,ai,2,...,ai,kia_{i,1},a_{i,2},...,a_{i,k_i} are the indices of these kik_i subsequent problems.

Output Format

If all problems can be answered correctly, output AK. Otherwise, output the maximum reward value that Xiaodou can obtain.

1 3
1 0
2 1 3
3 0
AK
1 6
1 2 2 3
2 1 4
3 1 4
4 1 6
5 0
6 0
5

Hint

For 10%10\% of the testdata, 1<n,m101<n,m\leq10.

For 20%20\% of the testdata, 1<n,m1001<n,m\leq100.

For 100%100\% of the testdata, 1<n50,1<m500,vi109,ki,ai,jm1<n\leq50,1<m\leq500,v_i\leq10^9,k_i,a_{i,j}\leq m.

Translated by ChatGPT 5