问题 A: Almost Acyclic

内存限制:512 MB 时间限制:10 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

We call a connected undirected graph almost-acyclic, if the graph has no cycles, or all the simple cycles in it share at least one common point.

You are given a complete undirected graph �=(�,�)G=(V,E) with n vertices. Each edge (�,�)(i,j) has a weight ��,�wi,j. Calculate (�(�)f(G) is 11 if G is almost-acyclic, or 00 otherwise):



输入格式

The first line contains a single integer T (1≤�≤161T16), denoting the number of test cases.

For each test case, the first line contains an integer n (1≤�≤161n16).

The next n lines each contains n integers. The j-th number in the i-th line denotes ��,�wi,j (0≤��,�<109+70wi,j<109+7).

It is guaranteed that ��,�=��,�wi,j=wj,i��,�=0wi,i=0.

It is guaranteed that for each 1≤�≤161i16, there is at most one test case satisfying �=�n=i.

输出格式

For each test case, output one line with an integer denoting the answer.

输入样例 复制

2
3
0 1 2
1 0 1
2 1 0
5
0 1 0 1 1
1 0 1 1 1
0 1 0 1 0
1 1 1 0 1
1 1 0 1 0

输出样例 复制

7
120