102586: [AtCoder]ABC258 G - Triangle

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

You are given a simple undirected graph $G$ with $N$ vertices.

$G$ is given as the $N \times N$ adjacency matrix $A$. That is, there is an edge between Vertices $i$ and $j$ if $A_{i,j}$ is $1$, and there is not if $A_{i,j}$ is $0$.

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

Constraints

  • $3 \le N \le 3000$
  • $A$ is the adjacency matrix of a simple undirected graph $G$.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_{1,1}A_{1,2}\dots A_{1,N}$
$A_{2,1}A_{2,2}\dots A_{2,N}$
$\vdots$
$A_{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)$ satisfy the condition.

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

Thus, the answer is $2$.


Sample Input 2

10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000

Sample Output 2

0

Input

题意翻译

给你一个简单的无向图,其中有 $N$ 个顶点。用一个 的 $N\times N$ 邻接矩阵 $A$ 来表示。如果 $A_{i,j}=1$ ,则表示 $i$ 到 $j$ 有边相连,如果 $A_{i,j}=0$ ,则表示 $i$ 到 $j$ 无边相连。 求三角形 $(i,j,k)$ 的个数,满足 $1\leq i < j < k\leq n$,且 $i$ 与 $j$ 有边相连,$i$ 与 $k$ 有边相连,$j$ 与 $k$ 有边相连。

Output

得分:600分

问题描述

给你一个有N个顶点的简单无向图G。

G是以$N \times N$邻接矩阵$A$给出的。也就是说,如果$A_{i,j}$为1,则顶点i和j之间有一条边,如果$A_{i,j}$为0,则没有边。

找出满足$1 \le i < j < k \le N$的整数三元组$(i,j,k)$的数量,使得顶点i和j之间有一条边,顶点j和k之间有一条边,顶点i和k之间有一条边。

约束

  • $3 \le N \le 3000$
  • $A$是简单无向图G的邻接矩阵。
  • 输入中的所有值都是整数。

输入

输入以标准输入的形式给出,如下所示:

$N$
$A_{1,1}A_{1,2}\dots A_{1,N}$
$A_{2,1}A_{2,2}\dots A_{2,N}$
$\vdots$
$A_{N,1}A_{N,2}\dots A_{N,N}$

输出

打印答案。


样例输入1

4
0011
0011
1101
1110

样例输出1

2

$(i,j,k)=(1,3,4),(2,3,4)$满足条件。

$(i,j,k)=(1,2,3)$不满足条件,因为顶点1和2之间没有边。

因此,答案为2。


样例输入2

10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000

样例输出2

0

加入题单

算法标签: