[Jsoi2010]连通数

floyd+bitset传递闭包

#include 
#include 
using namespace std;
const int maxn = 2000 + 10;
int n;
bitset dis[maxn];
char s[maxn];
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%s", s + 1);
        for(int j = 1; j <= n; j++)
            if(s[j] == '1' || i == j) dis[i][j] = true;
    }
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            if(dis[i][k]) dis[i] |= dis[k];
    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans += dis[i].count();
    printf("%d\n", ans);
    return 0;
}
 

转载于:https://www.cnblogs.com/ruoruoruo/p/7805252.html

  

你可能感兴趣的:([Jsoi2010]连通数)