#P9170. Alice and Bob's Paper Game
Alice and Bob's Paper Game
Alice and Bob's Paper Game
Alice and Bob play a game with paper slips. Initially, each has an empty paper. In total there are rounds. In each round both players will write one positive integer in the range on their paper. Alice writes her number first and Bob writes later after seeing Alice’s paper. However, there are restrictions. In round , Alice must choose her number from a given set and Bob must choose his number from a given set . It is guaranteed that (1\le |S_i|,|T_i|\le 2). Moreover, Bob must guarantee that his numbers are pairwise distinct.
Alice loves similarity so she wants as many indices with as possible, while Bob (subject to his distinctness constraint) wants to minimize the number of indices with . In other words, if we define [ X=|{ i:; 1\le i\le n \text{ and } a_i=b_i}|, ] then under optimal play we have:
- Alice tries to maximize (X),
- Bob, while ensuring that (b_1,\dots,b_n) are distinct, tries to minimize (X).
Furthermore, note that Bob writes his numbers after seeing Alice’s choices. Thus, in rounds where his set has exactly one element (a forced round), he has no choice; and naturally, if the forced number is available in , Alice will choose it to force a match. In rounds where , Bob will try to avoid a match by picking an element different from , but his options may be limited by the overall distinctness requirement. In particular, if , then Alice can choose a number from the intersection. In such rounds Bob can choose the other number as a safe option unless conflicts force him to choose (thereby increasing (X)). On the other hand, if , Bob cannot cause a match in that round.
Your task is as follows. First, determine if Bob can guarantee that the numbers he writes are pairwise distinct. If not, output -1. Otherwise, assuming both players play optimally, compute the final value of (X).
All formulas must be formatted in (\LaTeX).
inputFormat
The first line contains two integers \(n\) and \(m\) \((1\le n\le 50,\; 1\le m\le 50)\), representing the number of rounds and the upper bound.
The following \(n\) lines describe the sets \(S_i\). Each line begins with an integer \(k\) (\(1\le k\le 2\)) followed by \(k\) distinct integers in the range \([1,m]\) that form \(S_i\).
The next \(n\) lines describe the sets \(T_i\). Each line begins with an integer \(k\) (\(1\le k\le 2\)) followed by \(k\) distinct integers in the range \([1,m]\) that form \(T_i\).
outputFormat
If Bob cannot guarantee that his \(n\) numbers are pairwise distinct, output -1
. Otherwise, output a single integer, the value of \(X\) (the number of rounds in which \(a_i=b_i\)) when both players play optimally.
sample
3 5
1 1
2 2 3
2 3 5
1 1
2 2 4
2 1 2
1