Language: C++

#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

const ll max_n = 100005;
ll N,M;
vector<ll> A,B;
unordered_set<pii> st[4];
vector<vector<ll>> g;
unordered_set<ll> d[max_n][4];

int main(){
    cin >> N >> M;
    g.resize(N);
    A.resize(M);
    B.resize(M);
    rep(i,M){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        g[A[i]].pb(B[i]);
        g[B[i]].pb(A[i]);
    }

    rep(i,N){
        queue<pii> que;
        que.push(pii(0,i));
        vector<int> vis(N,0);
        vis[i] = true;
        //cerr << i << endl;
        while(!que.empty()){
            int dis = que.front().fi;
            int u = que.front().se;
            que.pop();
            if(i!=u and dis<=3){
                st[dis].insert(pii(min(i,u),max(i,u)));
            }
            if(dis == 3) continue;
            for(int v : g[u]){
                int nd = dis+1;
                que.push(pii(nd,v));
            }
        }
    }

    for(auto p : st[1]){
        if(st[3].count(p)){
            st[3].erase(p);
        }
    }

    rep(i,4){
        for(pii p : st[i]){
            int u=p.fi,v=p.se;
            d[u][i].insert(v);
            d[v][i].insert(u);
        }
    }

    //rep(i,4) cerr << st[i] << endl;

    while(1){
        set<pii> st2;
        for(pii p : st[3]){
            if(st[1].count(p)){
                continue;
            }
            ll u = p.fi,v=p.se;
            d[u][1].insert(v);
            d[v][1].insert(u);
            st[1].insert(pii(min(u,v),max(u,v)));
            for(ll nv : d[v][2]){
                if(u==nv) continue;
                if(st[1].count(pii(min(u,nv),max(u,nv)))) continue;
                d[u][3].insert(nv);
                st2.insert(pii(min(u,nv),max(u,nv)));
            }
            for(ll nu : d[u][2]){
                if(v==nu) continue;
                if(st[1].count(pii(min(v,nu),max(v,nu)))) continue;
                d[v][3].insert(nu);
                st2.insert(pii(min(v,nu),max(v,nu)));
            }
        }
        swap(st2,st[3]);
        //cerr << st2 << endl;
        if(st[3].empty()) break;
    }

    //cout << st[1] << endl;
    cout << st[1].size() - M << endl;
}


Compiler output:
a.cc:39:24: error: use of deleted function 'std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = std::pair<long long int, long long int>; _Hash = std::hash<std::pair<long long int, long long int> >; _Pred = std::equal_to<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
   39 | unordered_set<pii> st[4];
      |                        ^
In file included from /usr/include/c++/14/unordered_set:41,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:189,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_set.h:142:7: note: 'std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = std::pair<long long int, long long int>; _Hash = std::hash<std::pair<long long int, long long int> >; _Pred = std::equal_to<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]' is implicitly deleted because the default definition would be ill-formed:
  142 |       unordered_set() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_set.h:142:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, true, true>]'
In file included from /usr/include/c++/14/bits/unordered_map.h:33,
                 from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, true, true>]' is implicitly deleted because the default definition would be ill-formed:
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<long long int, long long int>; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, true, true>]'
In file included from /usr/include/c++/14/bits/hashtable.h:35:
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<long long int, long long int>; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<long long int, long long int> >; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, true, true>]' is implicitly deleted because the default definition would be ill-formed:
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<long long int, long long int>; _ExtractKey = std::__detail::_Identity; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<long long int, long long int> >]':
/usr/include/c++/14/bits/hashtable_policy.h:1328:7:   required from here
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::pair<long long int, long long int> >::hash()'
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<long long int, long long int> >::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::pair<long long int, long long int>, false>::__hash_enum()'
/usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::pair<long long int, long long int>; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<long long int, long long int>; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<long long int, long long int>; _Value = std::pair<long long int, long long int>; _ExtractKey = std::__detail::_Identity; _Hash = std::hash<std::pair<long long int, long long int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<long long int, long long int> >, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<long long int, long long int> >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1242 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::pair<long long int, long long int> >::~hash()'
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<long long int, long long int> >::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<long long int, long long int>; bool <anonymous> = false]' is private within this context
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::__detail::_Identity, std::hash<std::pair<long long int, long long int> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()'
/usr/include/c++/14/bits/hashtable_policy.h:1306:12: note: 'std::__detail::_Hash_code_base<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::__detail::_Identity, std::hash<std::pair<long