#P8893. 「UOI-R1」智能推荐
「UOI-R1」智能推荐
Background
The testdata has been strengthened.
Problem Description
There are now problems.
The days are numbered starting from . Each day you may solve several problems. You can only solve problems that have been recommended before or are recommended on that day (each problem can be solved at most once). On day , the intelligent recommendation system will recommend problems.
The recommendation rules are as follows:
For problem , if it can possibly be recommended, there will be a problem set . If and only if you have solved every problem in , and among them there is at least one problem solved on the current day, then problem will be recommended on the next day.
You want to solve problem . What is the earliest day on which you can achieve this?
Input Format
The first line contains three integers , with meanings as described in the statement.
The second line contains integers, indicating the indices of the problems recommended on day .
The third line contains an integer , indicating that there are recommendation rules.
The next lines each contain one rule, in the following format:
An integer , the index of the problem to be recommended. Then an integer , the number of problems that must be solved in order for this problem to be recommended. Then integers , representing each problem that must be solved.
Output Format
Output one integer, the minimum day on which you can achieve the goal.
If problem can never be solved no matter what, output -1.
5 5 2
1 2
3
3 2 1 2
4 3 1 2 3
5 3 1 3 4
3
1 1 1
1
0
0
7 7 2
1 2
2
3 2 1 2
6 2 1 2
-1
见文件附件的 rec4.in
见文件附件的 rec4.ans
Hint
[Sample Explanation #1]
On day , problems were recommended, and both were solved.
On day , problem was recommended and solved.
On day , problem was recommended and solved.
On day , problem was recommended, which is problem , and it was solved.
So problem can be solved by day .
[Sample Explanation #2]
On day , problem was recommended, which is problem , and it was solved.
So it was completed on day .
[Constraints]
Let denote, in the -th recommendation rule, the total number of problems that must be solved if is to be recommended.
For of the data, it is guaranteed that .
For of the data, it is guaranteed that there are no cycles.
For of the data, it is guaranteed that , . All are pairwise distinct, and for each , all are pairwise distinct, and all are pairwise distinct.
Translated by ChatGPT 5