卡常96分,最后一个点差0.10s
#include<bits/stdc++.h>
using namespace std;
const int po=1e4-1;
unordered_map<long long,int> mp;
unordered_map<long long,vector<int> > op;
int n,m,ans=0,uu[50004],vv[50004],ww[50004];
long long hsh(int u,int v,int w)
{
return 1LL*u*po*po+v*po+w;
}
void work1(int a,int b,int c)
{
for(int d:op[hsh(0,a,b)])
{
if(d<=c)continue;
if(mp[hsh(a,c,d)]==1&&mp[hsh(b,c,d)]==1&&mp[hsh(a,b,d)]==1)
ans++;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
n=m;
int i=0;
while(m--)
{
i++;
cin>>uu[i]>>vv[i]>>ww[i];
mp[hsh(uu[i],vv[i],ww[i])]=1;
op[hsh(0,uu[i],vv[i])].push_back(ww[i]);
}
i=0;
while(n--)
{
i++;
work1(uu[i],vv[i],ww[i]);
}
cout<<ans;
return 0;
}