Escolar Documentos
Profissional Documentos
Cultura Documentos
The Three Bit Computer is a huge failure in spite of
ontinuing eorts of Byteland's leading
s
ientists, but now they have a new and powerful idea: the Quantum Three Bit Computer (QTBC).
TBC
an now be regarded a warm-up before the real thing the QTBC.
They predi
t that the new ma
hine will have the power, blah, blah., many silly problems still to
solve, blah, blah. Now, let us get to the point.
The initializationpro
edure is again a major issue, but with quantum
omputers it is a
ompletely
dierent story. The trouble now is that everything you do has side ee
ts, i.e., it inuen
es everything
else. Taking
are of this is very time
onsuming and initializing the memory bit by bit is simply
impossible. But there is another approa
h. The s
ientists have developed large s
ale
ontrolled
impulses (LSCI), whi
h inuen
e all the memory bits at the same time, and moreover, it is known
exa
tly what their inuen
e is. They are also very fast, so emitting even a large number of impulses
is better then initializingthe memory bit by bit. The rst question to
onsider is whether there exist
a sequen
e of impulses that will zero the whole memory. Your task is to write a
omputer program
to answer this question.
More formally, ea
h memory bit
an be in one of states numbered . The LSCI
0; : : : ; n 1
impulse
hanges all the bits in exa
tly the same way, i.e. it
an be viewed as a fun
tion
n
:
g. For example, means that if the impulse is emitted,
f f
3 5
k . You have to nd out if there exists a sequen
e of impulses that brings all the bits to
state regardless of their initial state.
f1 ; : : : ; f
Task
Write a program that:
reads the des
riptions of the impulses available,
he
ks if zeroing the memory is possible,
writes the answer to the output le.
Input
The input le bit2.in
an
ontain several test
ases. The rst line of the input le
ontains a
single positive integer , , the number of test
ases. The des
ription of the test
ases
(1 10)
follows. Des
ription of a single test
ase starts with a line
ontaining two positive integers , ,
T T
1 200 1 5
number of dierent impulses that
an be emitted. The next lines
ontain the des
ription of the
n k n k
impulses, the -th line
ontains the des
ription of the -th impulse. The des
ription of an impulse
k
is a sequen
e of integers des
ribing the inuen
e has on the state of any memory
i i f
f (0) : : : f (n 1)
bit. These integers are separated by single spa
es.
f
1
Output
The output le bit2.out should have lines, one for ea
h test
ase. The -th line should
onsist of
a single word YES if zeroing the memory in the -th test
ase if possible, or NO otherwise.
T i
Example
For the input le bit2.in: the
orre
t result is the output le bit2.out:
2 NO
5 2 YES
1 2 3 4 0
2 3 4 0 1
5 2
1 2 3 4 0
3 3 4 0 1