#P15737. [JAG 2024 Summer Camp #2] I Love Square Number

[JAG 2024 Summer Camp #2] I Love Square Number

题目描述

Consider a graph with N(N+1)2\frac{N(N+1)}{2} vertices and 3N(N1)2\frac{3N(N-1)}{2} edges, where NN is an integer greater than or equals to 22.

  • The set of vertices is {(i,j)1iN,1ji}\{(i, j) \mid 1 \leq i \leq N, 1 \leq j \leq i\}.
  • There is an edge with weight ai,ja_{i,j} between (i,j)(i, j) and (i+1,j)(i + 1, j) (for 1iN11 \leq i \leq N - 1 and 1ji1 \leq j \leq i).
  • There is an edge with weight bi,jb_{i,j} between (i,j)(i, j) and (i+1,j+1)(i + 1, j + 1) (for 1iN11 \leq i \leq N - 1 and 1ji1 \leq j \leq i).
  • There is an edge with weight ci,jc_{i,j} between (i,j)(i, j) and (i,j+1)(i, j + 1) (for 2iN2 \leq i \leq N and 1ji11 \leq j \leq i - 1).

For a simple path in this graph, the weight of the path is defined as the product of the weights of the edges that the path traverses.

Determine the number of unordered pairs of distinct vertices {s,t}\{s, t\} such that any simple path from ss to tt has a weight that is a square number.

输入格式

The input is given in the following format:

$$\begin{aligned} &N \\ &a_{1,1} \\ &a_{2,1} \ a_{2,2} \\ &\vdots \\ &a_{N-1,1} \ \cdots \ a_{N-1,N-1} \\ &b_{1,1} \\ &b_{2,1} \ b_{2,2} \\ &\vdots \\ &b_{N-1,1} \ \cdots \ b_{N-1,N-1} \\ &c_{2,1} \\ &c_{3,1} \ c_{3,2} \\ &\vdots \\ &c_{N,1} \ \cdots \ c_{N,N-1} \end{aligned} $$
  • 2N1,0002 \leq N \leq 1,000
  • 1ai,j,bi,j,ci,j1061 \leq a_{i,j}, b_{i,j}, c_{i,j} \leq 10^6
  • All input values are integers.

输出格式

Output the answer.

2
1
2
2
1
3
1
2 3
4
5 6
7
8 9
0