Gym - 100342J Triatrip (bitset求三元环个数)

https://vjudge.net/problem/Gym-100342J

题意:
给出一个邻接矩阵有向图,求图中的三元环的个数。

 

思路:

利用bitset暴力求解,记得最后需要/3。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<vector>
 6 #include<stack>
 7 #include<queue>
 8 #include<cmath>
 9 #include<map>
10 #include<set>
11 #include<bitset>
12 using namespace std;
13 typedef long long ll;
14 typedef pair<int,int> pll;
15 const int INF = 0x3f3f3f3f;
16 const int maxn=1500+5;
17 
18 char s[maxn];
19 bitset<maxn> bit1[maxn],bit2[maxn];
20 
21 int main()
22 {
23     //freopen("in.txt","r",stdin);
24     freopen("triatrip.in","r",stdin);
25     freopen("triatrip.out","w",stdout);  
26     int n;
27     scanf("%d",&n);
28     for(int i=0;i<n;i++)
29     {
30         scanf("%s",s);
31         for(int j=0;j<n;j++)
32         {
33             if(s[j]=='+')  bit1[i].set(j),bit2[j].set(i);
34             //bit1记录i能够到达的点,bit2记录能够到达j的点
35         }
36     }
37     ll ans = 0;
38     for(int i=0;i<n;i++)
39     {
40         for(int j=0;j<n;j++)
41         {
42             if(bit1[i][j])
43             {
44                 ans+=(bit1[j]&bit2[i]).count();
45             }
46         }
47     }
48     printf("%lld\n",ans/3);
49     return 0;
50 }

 

转载于:https://www.cnblogs.com/zyb993963526/p/7482086.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值