跳到正文

个人记录

三元环计数(bitset)

zzr8178541919约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年12月16日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<bitset>
#define int long long
#define reg register
using namespace std;
const int maxn=4e6+5;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
bitset<1505> a[1505],b[1505];
int n,m;
signed main()
{	
	n=read(),m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		b[x][y]=1;
		a[y][x]=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(b[i][j])
			{
				ans=ans+(b[j] & a[i]).count();
			}
		}
	}	
	cout<<ans/3<<endl;
 	return 0;
}
/*
6 6
1 2
2 3
3 1
4 5
5 6 
6 4
*/
原文