#P11230. Chain Game Feasibility
Chain Game Feasibility
Chain Game Feasibility
In this problem, there are \(n\) players participating in a chain game. The \(i\)-th player has an integer sequence \(S_i\) as his "word bank". A game consists of several rounds. In each round the rules are as follows:
- One of the \(n\) players, say player \(p\), is chosen to play this round with his sequence \(S_p\). If this is not the first round of the game, then the player chosen for this round must be different from the one in the previous round (but may have been chosen earlier).
- The chosen player \(p\) selects a contiguous subarray \(A\) from \(S_p\) with length in the interval \([2, k]\) (\(k\) is a given constant). If this is the first round, then \(A\) must start with element \(1\). Otherwise, \(A\) must start with the last element of the previous round's chosen subarray.
Note that a contiguous subarray means that \(A\) is obtained from \(S_p\) by possibly deleting some elements from the beginning and/or the end.
In order to encourage cooperation, a total of \(q\) tasks are given. The \(j\)-th task requires that a game is played with exactly \(r_j\) rounds and the last element of the last round's subarray is exactly \(c_j\). Your task is to determine for each of the \(q\) tasks whether there exists a valid game process satisfying the conditions.
Input/Output Formats are described below.
inputFormat
The first line contains three integers \(n\), \(k\) and \(q\) (number of players, maximum length of chosen subarray, and number of tasks).
Then follow \(n\) lines. The \(i\)-th of these lines begins with an integer \(L_i\) (the length of sequence \(S_i\)), followed by \(L_i\) integers representing the sequence \(S_i\).
Then follow \(q\) lines, each containing two integers: \(r_j\) and \(c_j\) (number of rounds in the game and the required last element of the final round).
outputFormat
For each query, output a line containing YES
if there exists a valid game process satisfying the conditions, or NO
otherwise.
sample
2 3 3
3 1 2 3
3 1 3 2
1 3
2 2
2 3
YES
YES
NO
</p>