#abc258g. G - Triangle

G - Triangle

Score : 600600 points

问题描述

给定一个包含 NN 个顶点的简单无向图 GG

GG 通过一个 N×NN \times N 的邻接矩阵 AA 给出。即,若 Ai,jA_{i,j}11,则表示顶点 ii 和顶点 jj 之间存在一条边;若 Ai,jA_{i,j}00,则表示它们之间不存在边。

找出满足条件 1i<j<kN1 \le i < j < k \le N 的整数三元组 (i,j,k)(i, j, k) 的数量,使得在顶点 ii 和顶点 jj 之间、顶点 jj 和顶点 kk 之间以及顶点 ii 和顶点 kk 之间都存在边。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a simple undirected graph GG with NN vertices.

GG is given as the N×NN \times N adjacency matrix AA. That is, there is an edge between Vertices ii and jj if Ai,jA_{i,j} is 11, and there is not if Ai,jA_{i,j} is 00.

Find the number of triples of integers (i,j,k)(i,j,k) satisfying 1i<j<kN1 \le i < j < k \le N such that there is an edge between Vertices ii and jj, an edge between Vertices jj and kk, and an edge between Vertices ii and kk.

Constraints

  • 3N30003 \le N \le 3000
  • AA is the adjacency matrix of a simple undirected graph GG.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1,1A1,2A1,NA_{1,1}A_{1,2}\dots A_{1,N}

A2,1A2,2A2,NA_{2,1}A_{2,2}\dots A_{2,N}

\vdots

AN,1AN,2AN,NA_{N,1}A_{N,2}\dots A_{N,N}

Output

Print the answer.

Sample Input 1

4
0011
0011
1101
1110

Sample Output 1

2

(i,j,k)=(1,3,4),(2,3,4)(i,j,k)=(1,3,4),(2,3,4) satisfy the condition.

(i,j,k)=(1,2,3)(i,j,k)=(1,2,3) does not satisfy the condition, because there is no edge between Vertices 11 and 22.

Thus, the answer is 22.

Sample Input 2

10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000

Sample Output 2

0

update @ 2024/3/10 10:58:28