Under construction

Still being built. Things may change

Fairies and Witches

Time limit40sMemory limit1024 MB

Summary
Count the sets of sticks with no shared endpoints whose lengths can form a convex polygon with non-zero area.
Level

Medium7 of 10

Topics
Graph, Combinatorics, Dynamic programming, Sorting
Solved
No attempts yet

Problem

Pari is a powerful fairy who fights to protect Fairyland from evil witches. The witches grow stronger every day, so Pari must arrange magical sticks into a convex polygon with non-zero area to cast a protection spell. Pari cannot use whichever sticks she wants, though. The sticks in Fairyland form a graph in which the edges are sticks and the nodes are endpoints of one or more sticks. The sticks touch each other only at endpoints, since they are magical. When Pari removes a stick to use in her spell, every stick that shared a node with it disappears forever and can no longer be used. Pari wonders how many distinct subsets of sticks can be removed and used to form a convex polygon with non-zero area. All sticks are distinct, even those with the same length. Two subsets are distinct if at least one stick is in one but not the other. A subset is valid only if there is a way to remove all of its sticks from the graph without any of them disappearing.

Input

The first line contains the number of test cases TT. Each test case begins with a line containing the integer NN, the number of nodes in the graph. Then NN lines follow, each containing NN integers. The jj-th value on the ii-th line is Li,jL_{i,j}, the length of the stick with endpoints at nodes ii and jj, or 0 if there is no such stick.

Output

For each test case, output one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the number of valid subsets described above.

Limits

1≤T≤1001 \le T \le 100. 0≤Li,j≤10000 \le L_{i,j} \le 1000 for all i,ji, j. Li,i=0L_{i,i} = 0 for all ii. Li,j=Lj,iL_{i,j} = L_{j,i} for all i,ji, j.

Examples1

  1. Example 1

    Input
    4
    6
    0 1 0 0 0 0
    1 0 1 0 0 0
    0 1 0 1 0 0
    0 0 1 0 1 0
    0 0 0 1 0 1
    0 0 0 0 1 0
    6
    0 2 0 0 0 0
    2 0 0 0 0 0
    0 0 0 3 0 0
    0 0 3 0 0 0
    0 0 0 0 0 4
    0 0 0 0 4 0
    6
    0 1 0 0 0 0
    1 0 0 0 0 0
    0 0 0 2 0 0
    0 0 2 0 0 0
    0 0 0 0 0 4
    0 0 0 0 4 0
    6
    0 1 1 1 1 1
    1 0 0 0 0 0
    1 0 0 0 0 0
    1 0 0 0 0 0
    1 0 0 0 0 0
    1 0 0 0 0 0
    
    Expected output
    Case #1: 1
    Case #2: 1
    Case #3: 0
    Case #4: 0