# 这不是Floyd

4
1
1
2
1 0
0 1
2
1 1
1 1
3
1 1 1
0 1 1
0 0 1

0
0
2
2

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define sqr(x) (x)*(x)
#define inf 1000000000
#define ll long long
#define mod 1000000
#define N 1000005
using namespace std;
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int ans,num,tot,tim,top,len;
bool flag_stk[2005],flag[2005],ff[2005];
int c[2005],f[2005],sum[2005],l[10000],r[10000],p[205][205],a[205][205];
void tarjan(int u)
{
tim++;flag_stk[u]=1;
dfn[u]=low[u]=tim;
stk[++top]=u;
{
int v=ret[i];
if (dfn[v]==0)
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if (flag_stk[v]) low[u]=min(low[u],dfn[v]);
}
if (dfn[u]==low[u])
{
num=num+1;sum[num]=1;f[num]=num;bool flag=0;int s=0;
while (stk[top]!=u)
{
flag_stk[stk[top]]=0;
c[stk[top]]=num;flag=1;
top--;s++;
}
flag_stk[stk[top]]=0;
c[stk[top]]=num;
top--;s++;ans+=s;if (!flag) ans--;
}
}
void solve()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j]==1&&c[i]!=c[j])
{
len++;
l[len]=c[i];
r[len]=c[j];
p[c[i]][c[j]]++;
}
ans+=len;
for(int k=1;k<=num;k++)
for(int i=1;i<=num;i++)
for(int j=1;j<=num;j++)
if(p[i][k]>0&&p[k][j]>0) p[i][j]=p[i][j]+p[i][k]*p[k][j];
for(int i=1;i<=len;i++)
{
p[l[i]][r[i]]--;
if(p[l[i]][r[i]]==0) p[l[i]][r[i]]++;
else ans--;
}
}
int main()
{
while (T--)
{
memset(p,0,sizeof(p));
for (int i=1;i<=n;i++)
{
low[i]=dfn[i]=0;
for (int j=1;j<=n;j++)
{
if (a[i][j]) ins(i,j);
}
}
for (int i=1;i<=n;i++)
{
flag[i]=0;
if (dfn[i]==0) tarjan(i);
}
solve();
printf("%d\n",ans);
}
return 0;
}