The problem is as easy as that someone can solve in 1 minute.
Although the problem is quite simple, unfortunately the problem description is unpredictable hard.
MapReduce is a distributed framework introduced by Google since 2004, for computing certain kinds of distributable problems using a large number of computing nodes. MapReduce classified its computing nodes (WORKERs) into MAPPERs and REDUCERs. Due to the network structure of MapReduce is still too complex, some kind of engineer are going to design a simple protocol between Mappers and Reducers, called Ximple MapReduce.
In Ximple MapReduce network, the original data are stored in some Reducers. In each computing phase, each Reducer reduce the data he stored and received from Mappers, then reduces the data and passes the result to another Mapper. Each Mapper received the data from one Reducer, and the only thing he do is passing the data to another Reducer. In each phase, every worker can only do one job. Finally, all data need to be reduced and passed to Central Mapper with ID 0.
Unfortunately, Ximple MapReduce is not much reliable between its workers. If some worker crashes, the total computing got failures. Engineer now can detect the failure, but he need to know the structure network of this computing phase to rebuild computing. One of the method is to take a SNAPSHOT of this network. The snapshot is some characteristic of the network, and a reasonable approach is to compute the determinant of the network, which is defined by the determinant of its adjacency matrix.
Hence, till now, our Engineer are still working on computing the determinant of the network. Because this is not a easy procedure, could you write a program to help our Engineer?
The first line of the input file contains an integer T indicating the number of test cases to follow. T <= 20.
Each test case contains exactly one line. The first input of each test cases is an integer N, indicating number of workers in the network, N <= 300. All worker with ID between 0 and N-1. Mappers has even ID and Reducers has odd one.
There are following N-1 integers P1, P2, ... Pi, ..., P_(N-1). The worker i has to pass its data to the worker Pi. The worker with ID 0 is the Central Mapper, it has no need no pass the result to other workers.
For each test case, output the determinant of the network in the test case.
2 2 0 6 0 1 2 3 4
-1 -1
Migrated from old NTUJ.
malicious TAs
No. | Testdata Range | Score |
---|