[BZOJ2208][JSOI2010]连通数(传递闭包+bitset)

正解好象是tarjan缩点处理。

 1 #include<cstdio>
 2 #include<bitset>
 3 #include<algorithm>
 4 #define rep(i,l,r) for (int i=l; i<=r; i++)
 5 using namespace std;
 6 
 7 const int N=2010;
 8 int n,ans;
 9 char x;
10 bitset<N>f[N];
11 
12 int main(){
13     scanf("%d",&n);
14     rep(i,1,n) rep(j,1,n) scanf(" %c",&x),f[i][j]=(x=='1')|(i==j);
15     rep(i,1,n) rep(j,1,n) if (f[j][i]) f[j]|=f[i];
16     rep(i,1,n) ans+=f[i].count();
17     printf("%d\n",ans);
18     return 0;
19 }

猜你喜欢

转载自www.cnblogs.com/HocRiser/p/9062671.html