#includeusing namespace std;int n, ans, c, i, j, k;bitset<2007>a[2005];int read() { for(c = getchar(); !isdigit(c); c = getchar()); return c-'0';}int main() { scanf("%d", &n); for (i = 1; i <= n; a[i][i] = 1, ++i) for (j = 1; j <= n; ++j) a[i][j] = read(); for(k = 1; k <= n; ++k) for(i = 1; i <= n; ++i) if (a[i][k]) a[i] |= a[k]; for(i = 1; i <= n; ++i) ans += a[i].count(); cout << ans; return 0;}
注意枚举顺序
正常的floyd是 k i j枚举 k是中间点优化的时候就不用枚举j(终点)了