Graph Automata Player
InterviewTime limit10sMemory limit512 MB
Given a Boolean graph update rule and a state at time 0, decide whether a state at time -T exists and is unique, by inverting the adjacency matrix over GF(2).
- Level
Medium7 of 10
- Topics
- Matrix, Math, Bit manipulation
- Solved
- No attempts yet
Statement
You and your grandma are playing with graph automata, a generalization of cellular automata.
A graph automaton is described by a graph. Each vertex of the graph has a value that changes over time, and that value is either 0 or 1. Between any two vertices there is at most one edge, and a self-loop may exist.
Vertex values change regularly according to the following rule. At time t+1, the value of vertex i is 1 if and only if the number of edges from vertex i to a vertex whose value at time t is 1 is odd; otherwise it is 0.
Your forgetful grandma has forgotten the past states of the automaton. Your task is to write a program that recovers past states from the current time and state. Time machines cost far too much. There may be several candidates or no consistent state. In those cases you must print an appropriate error message.
Input
The input is formatted as follows.
N
a11 ... a1N
:
:
aN1 ... aNN
v1
:
:
vN
T
The first line contains one integer N (2 ≤ N ≤ 300). N is the number of vertices. The next N lines give the adjacency matrix of the graph. If the (i,j)-th element is 1, there is an edge from vertex i to vertex j; otherwise there is none. The next N lines give the value vector of the vertices. The i-th element is the value of vertex i at time 0. Each element of the matrix and the vector is 0 or 1. The last line contains one integer T (1 ≤ T ≤ 100,000,000). -T is the time whose state your grandma wants to know.
Output
Print the value vector at time -T on one line, separated by one space, as follows.
v1 ... vN
Each value must be separated by one space. If no consistent value vector exists, print none on one line. If there are several candidates and the solution is not unique, print ambiguous on one line.