题目链接:

http://codeforces.com/gym/100342

题意:

求三元环的个数

题解:

用bitset分别统计每个点的出度的边和入度的边。

枚举每一条边(a,b),计算以b为出度的边的终点构成的点集和以a为入度的边的起点够成的点集的交集,更新答案。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
using namespace std; const int maxn = ;
typedef __int64 LL; bitset<maxn> in[maxn], out[maxn], And;
char str[maxn][maxn]; int main() {
freopen("triatrip.in", "r", stdin);
freopen("triatrip.out", "w", stdout);
int n;
scanf("%d", &n);
for (int i = ; i < n; i++) scanf("%s", str[i]);
LL ans = ;
for (int i = ; i < n; i++){
for (int j = ; j < n; j++) {
if (str[i][j] == '+') {
in[j][i] = true;
out[i][j] = true;
}
}
}
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
if (str[i][j] == '+') {
And = (in[i]) & (out[j]);
ans += And.count();
}
}
}
printf("%I64d\n", ans / );
return ;
}
05-11 10:54
查看更多