#P9899. Almost Acyclic
Almost Acyclic
Almost Acyclic
Problem Description
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 with vertices. Each edge has a weight . Calculate ( is if is almost-acyclic, or otherwise):
$$\sum_{E'\subseteq E,\ G'=(V,E')} f(G')\prod_{(i,j)\in E'} w_{i,j}\mod{10^9+7} $$Input
The first line contains a single integer (), denoting the number of test cases. For each test case, the first line contains an integer (). The next lines each contains integers. The -th number in the -th line denotes (). It is guaranteed that , . It is guaranteed that for each , there is at most one test case satisfying .
Output
For each test case, output one line with an integer denoting the answer.
Sample Input
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
Sample Output
7
120
Source
2023“钉耙编程”中国大学生算法设计超级联赛(10)