#P4306. [JSOI2010] 连通数

    ID: 3241 远端评测题 300ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2010各省省选江苏枚举,暴力图的建立,建图连通块强连通分量,缩点概率论,统计

[JSOI2010] 连通数

Description

A metric for measuring the connectivity of a directed graph is the reachability count, defined as the number of ordered pairs of vertices in which the second is reachable from the first.

As shown in the figure:

Vertex 1 can reach 1, 2, 3, 4, 5. Vertex 2 can reach 2, 3, 4, 5. Vertex 3 can reach 3, 4, 5. Vertices 4 and 5 can only reach themselves.

Therefore, the reachability count of this graph is 1414.

Given a graph, please compute its reachability count.

Input Format

The first line contains the number of vertices, a positive integer NN.
Then follow NN lines, each containing NN characters. In the ii-th row and jj-th column, a 1 indicates there is a directed edge from ii to jj, and 0 indicates no edge.

Output Format

Output a single line with one integer, the reachability count of the graph.

3
010
001
100
9

Hint

For 100%100\% of the testdata, 1N20001 \le N \le 2000.

Translated by ChatGPT 5