Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<vector<pair<long long, long long> > > adj;
vector<long long> dist1, np1, dist2, np2;

void dijk(long long u, vector<long long> &d) {
  priority_queue<pair<long long, long long> > pq;
  pq.push(make_pair(0, u));

  while(!pq.empty()) {
    pair<long long, long long> curr = pq.top(); pq.pop();
    curr.first *= -1;
    if(d[curr.second] <= curr.first) continue;
    d[curr.second] = curr.first;
    for(long long i = 0; i<adj[curr.second].size(); ++i) {
      pair<long long, long long> p = adj[curr.second][i];
      if(d[p.first] <= d[curr.second]+p.second) continue;
      pq.push(make_pair(-(d[curr.second]+p.second), p.first));
    }
  }
}

void di2(long long u, vector<long long> &d, vector<ll> &np) {
  priority_queue<pair<ll, ll> > pq;
  for(ll i = 0; i<d.size(); ++i) {
    pq.push(make_pair(-d[i], i));
  }
  while(!pq.empty()) {
    ll curr = pq.top().second; pq.pop();
    for(ll i = 0; i<adj[curr].size(); ++i) {
      pair<ll, ll> p = adj[curr][i];
      if(d[p.first] == d[curr]+p.second) np[p.first] += np[curr];
    }
  }
}

vector<bool> processed;

void dfs(long long curr, vector<long long> &d, vector<long long> &np) {
  processed[curr] = true;
  for(long long i = 0; i<adj[curr].size(); ++i) {
    pair<ll, ll> p = adj[curr][i];
    if(!processed[p.first]) {
      dfs(p.first, d, np);
    }
  }
}

int main() {
  long long n, m; cin >> n >> m;
  long long s, t; cin >> s >> t;
  s--; t--;

  adj.resize(n);
  dist1.assign(n, 1e15);
  dist2.assign(n, 1e15);
  np1.resize(n);
  np2.resize(n);
  for(long long i = 0; i<m; ++i) {
    long long u, v, d; cin >> u >> v >> d;
    u--; v--;
    adj[u].push_back(make_pair(v, d));
    adj[v].push_back(make_pair(u, d));
  }

  np1[s] = 1;
  dijk(s, dist1);
  di2(s, dist1, np1);

  np2[t] = 1;
  dijk(t, dist2);
  di2(t, dist2, np2);

  /*
  for(ll i = 0; i<n; ++i) {
    cout << i << " " << dist1[i] << " " << dist2[i] << " " << np1[i] << " " << np2[i] << endl;
  }
  */
  ll ret = np1[t]*np1[t];
  for(ll i = 0; i<n; ++i) {
    if(dist1[i] == dist2[i]) {
      ret -= np1[i] * np2[i];
    }
  }
  //cout << "ret checkpoint " << ret << endl;
  for(ll i = 0; i<n; ++i) {
    for(ll j = 0; j<adj[i].size(); ++j) {
      ll u = i;
      ll v = adj[i][j].first;
      if(dist1[u] + adj[i][j].second != dist1[v] || dist2[v] + adj[i][j].second != dist2[u]) continue;
      /*
      cout << u << " " << v << endl;
      cout << dist1[u] << " " << dist1[v] << endl;
      cout << dist2[u] << " " << dist2[v] << endl;
      cout << endl;
      */
      if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      if(dist1[u] >= (dist1[t])/2 || dist2[v] >= (dist1[t])/2) continue;
      ret -= np1[u] * np2[v];
      /*
      if(dist1[u] >= dist2[v] && dist1[u] <= dist2[u]) {
        ret -= np1[u] * np2[v];
      }
      if(dist1[u] < dist2[v] && dist1[v] > dist2[v]) {
        ret -= np1[u] * np2[v];
      }
      */
    }
  }
  cout << ret << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:101:30: error: no match for 'operator+' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'})
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::move_iterator<_IteratorL>'
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
In file included 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/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'const _CharT*' and 'long long int'
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   mismatched types 'const _CharT*' and 'long long int'
  101 |       if(dist1[u] + dist2[v] + adj[i][j] != dist1[t]) continue;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3726 |     operator+(_CharT __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3726:5: note:   template argument deduction/substitution failed:
a.cc:101:40: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} i