# 解题报告：HDU_6184 Counting Stars (三元环计数)

（点数和<=3e5,边数和<=6e5,数据组数<=300）

#include<bits/stdc++.h>

#define LL long long
#define pii pair<LL,int>
#define fi first
#define se second
const int N = 3e5+10;
const int mod = 1e5+3;
using namespace std;

int num[N];
vector<int>G[N],pos;
vector< pii >M[mod];
inline LL code(LL a,LL b){if(a>b)swap(a,b);
return (a<<18)|b;
}
inline bool check(int a,int b){
LL k = code(a,b);int p = k % mod;
for(int i=0;i<M[p].size();i++)if(M[p][i].fi==k)return true;
return false;
}

LL k = code(a,b);int p = k % mod;
M[p].emplace_back(pii(k,0));
}
inline void add(int a,int b,bool f){
LL k = code(a,b);int p = k % mod;
for(int i=0;i<M[p].size();i++)if(M[p][i].fi==k){
++M[p][i].se;return ;
}
}

{
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;
}

int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==2){pos.clear();
for(int i=1;i<=n;i++)G[i].clear();
for(int i=0;i<mod;i++)M[i].clear();
for(int i=0,s,e;i<m;++i){
G[e].emplace_back(s);
}LL ans = 0 ; m = sqrt(m+0.5);
for(int i=1,a,b;i<=n;i++)
if(G[i].size()>m)pos.emplace_back(i);
else for(int j=0;j<G[i].size();j++)if(G[a=G[i][j]].size()>m||a>i)
for(int k=j+1;k<G[i].size();k++)if((G[b=G[i][k]].size()>m||b>i)&&check(a,b))