题解:P15754 [JAG 2025 Summer Camp #1] Dyad
link
Solution
首先,我们假设
对于 map 记录这样的数对的数量
但是如果
Code
:::success[code]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef double db;
typedef __int128 i128;
const ll inf=9e18,maxn=3e5+1;
const i128 Inf=1e35;
ll n,a[maxn],b[maxn],ans;
map<pair<ll,ll>,ll> mp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
if(a[i]>b[i]) swap(a[i],b[i]);
if(a[i]==b[i]) a[i]=b[i]=-1;
mp[{a[i],b[i]}]++;
}
for(pair<pair<ll,ll>,ll> m:mp)
{
ans+=m.second*(m.second-1)/2;
}
cout<<ans;
}
:::