eolymp
bolt
Try our new interface for solving problems
Məsələlər

Three Bit Computer strikes back

Three Bit Computer strikes back

The Three Bit Computer is a huge failure in spite of continuing e orts of Byteland’s leading scientists, but now they have a new and powerful idea: the Quantum Three Bit Computer (QTBC). TBC can now be regarded a warm-up before the real thing the QTBC. They predict that the new machine will have the power, blah, blah., many silly problems still to solve, blah, blah. Now, let us get to the point. The initialization procedure is again a major issue, but with quantum computers it is a completely different story. The trouble now is that everything you do has side e ects, i.e., it in uences everything else. Taking care of this is very time consuming and initializing the memory bit by bit is simply impossible. But there is another approach. The scientists have developed large scale controlled impulses (LSCI), which in uence all the memory bits at the same time, and moreover, it is known exactly what their in uence is. They are also very fast, so emitting even a large number of impulses is better then initializing the memory bit by bit. The rst question to consider is whether there exist a sequence of impulses that will zero the whole memory. Your task is to write a computer program to answer this question. More formally, each memory bit can be in one of \textbf{n} states numbered \textbf{0}, ..., \textbf{n-1}. The LSCI impulse \textbf{f} changes all the bits in exactly the same way, i.e. it can be viewed as a function \textbf{f}: \{\textbf{0}, ..., \textbf{n-1}\} → \{\textbf{0}, ..., \textbf{n-1}\}. For example, \textbf{f(3) = 5} means that if the impulse \textbf{f} is emitted, then every bit in state \textbf{3} will change its state to \textbf{5}. The scientists know how to emit several impulses \textbf{f_1}, ..., \textbf{f_k} . You have to find out if there exists a sequence of impulses that brings all the bits to state \textbf{0} regardless of their initial state. \textbf{Task} Write a program that: \begin{itemize} \item reads the descriptions of the impulses available, \item checks if zeroing the memory is possible, \item writes the answer to the output file. \end{itemize} \InputFile The input file can contain several test cases. The first line of the input file contains asingle positive integer \textbf{T}, (\textbf{1} ≤ \textbf{T} ≤ \textbf{10}), the number of test cases. The description of the test cases follows. Description of a single test case starts with a line containing two positive integers \textbf{n}, \textbf{k},(\textbf{1} ≤ \textbf{n} ≤ \textbf{200}, \textbf{1} ≤ \textbf{k} ≤ \textbf{5}), where \textbf{n} is the number of different states of memory bits and \textbf{k} is the number of different impulses that can be emitted. The next \textbf{k} lines contain the description of the impulses, the \textbf{i}-th line contains the description of the \textbf{i}-th impulse. The description of an impulse \textbf{f} is a sequence of integers \textbf{f(0)} ... \textbf{f(n-1)} describing the influence \textbf{f} has on the state of any memory bit. These integers are separated by single spaces. \OutputFile The output file should have \textbf{T} lines, one for each test case. The \textbf{i}-th line should consist of a single word \textbf{YES} if zeroing the memory in the \textbf{i}-th test case if possible, or \textbf{NO} otherwise.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 32 MiB
Giriş verilənləri #1
2
5 2
1 2 3 4 0
2 3 4 0 1
5 2
1 2 3 4 0
3 3 4 0 1
Çıxış verilənləri #1
NO
YES