题解
一道bitset优化floyd传递闭包裸题!
代码
#include<iostream>
#include<bitset>
#include<cstdio>
#include<cctype>
#define N 2010
using namespace std;
bitset<N> lnk[N];
int n,ans;
char ch[N];
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%s",ch+1);
for (int j=1;j<=n;j++)
lnk[i][j]=ch[j]=='1'||i==j;
}
for (int j=1;j<=n;j++)
for (int i=1;i<=n;i++)
if (lnk[i][j]) lnk[i]|=lnk[j];
for (int i=1;i<=n;i++) ans+=lnk[i].count();
printf("%d\n",ans);
return 0;
}