7607: I do not know Graph Theory!

内存限制:128 MB 时间限制:14 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

A tournament graph is a directed graph where there is exactly one edge between every two distinct vertices.

A strongly connected graph is a directed graph where there is a path between every two distinct vertices.

You are given a tournament graph. For each edge of the graph, find out whether the graph is strongly connected when that edge is reversed.

输入格式

The first line contains one integer T (1≤T≤40000), the number of test cases.
For each test case, the first line contains one integer n (2≤n≤5000), the number of vertices.
The next n−1 lines give out the compressed lower triangular matrix in the following way:
Each line contains an uppercase hexadecimal string, where the j-th hexadecimal of the i-th string Si,j=∑3k=02k×Ei+1,4j+k−3, and Ei,j=1 iff the direction of the edge between i,j is from i to j. All indices start from 1.
It is guaranteed that there are at most 3 test cases in which the n is larger than 10.
 

输出格式

For each test case, output n−1 lines in the same format of the input: Si,j=∑3k=02k×ansi+1,4j+k−3, and ansi,j=1 iff the graph is strongly connected when the edge between i,j is reversed.

输入样例 复制

2
3
0
2
6
1
3
7
F
F1

输出样例 复制

1
0
0
0
0
0
10