BZOJ 2208: [Jsoi2010]连通数【floyd】【bitset】

b i t s e t bitset bitset卡常很优秀吖

#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define db double
#define sg string
#define ll long long
#define rel(i,x,y) for(ll i=(x);i<(y);i++)
#define rep(i,x,y) for(ll i=(x);i<=(y);i++)
#define red(i,x,y) for(ll i=(x);i>=(y);i--)
#define res(i,x) for(ll i=head[x];i;i=nxt[i])
using namespace std;

const ll N=2e3+5;
const ll Inf=1e18;
const db Eps=1e-10;

char ch[N];ll n,ans;

bitset<N>f[N];

inline ll read() {
	ll x=0;char ch=getchar();bool f=0;
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return f?-x:x;
}

int main() {
	n=read();
	
	rep(i,1,n) {
		scanf("%s",ch+1);
		rep(j,1,n) if(ch[j]=='1'||i==j) f[i][j]=1;
	}

	rep(i,1,n) rep(j,1,n) if(f[j].test(i)) f[j]|=f[i];
		
	rep(i,1,n) ans+=f[i].count();

	printf("%lld\n",ans);

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值