Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e18+7;
ll MOD = 1e9+7;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist[2],taken,cou[2];
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N]={0};
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x){while(k <= siz){bit[k]+=x;k += k & -k;}}
ll BITq(ll k){ll s=0;while(k>=1){s+=bit[k];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s,ll k){pq.push(ii(0,s));dist[k][s] = 0;cou[k][s] = 1;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;for(auto v:adj2[u]){if(dist[k][v.F] > dist[k][u] + v.S){dist[k][v.F] = dist[k][u] + v.S;cou[k][v.F] = cou[k][u];pq.push(ii(dist[k][v.F],v.F));}else if(dist[k][v.F] == dist[k][u] + v.S){cou[k][v.F]+=cou[k][u];}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(a){pl("Yes");}else{pl("No");}}
void filesin(void){freopen("tracing.in","r",stdin);}
void filesout(void){freopen("tracing.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///ΑτΚοδερ ;)
int main(void){
    fastio;
    ll n,m;
    cin>>n>>m;
    ll s,t;
    cin>>s>>t;
    adj2.assign(n+5,vii());
    ll aa[m];
    ll bb[m];
    ll ww[m];
    f(i,0,m){
        ll a,b,w;
        cin>>a>>b>>w;
        adj2[a].pb(ii(b,w));
        adj2[b].pb(ii(a,w));
        aa[i] = a;
        bb[i] = b;
        ww[i] = w;
    }
    dist[0].assign(n+5,INF);
    dist[1].assign(n+5,INF);
    cou[0].assign(n+5,0);
    cou[1].assign(n+5,0);
    dijkstra(s,0);
    dijkstra(t,1);
    ll path = dist[0][t];
    ll ways = cou[0][t];
    ll ans = ways * ways;
  	ans %= INF;
    f(i,1,n+1){
        if(dist[0][i] == dist[1][i] && dist[0][i] + dist[1][i] == path){
          	ll num = (cou[0][i] * cou[1][i]) % INF
            ans -= (num * num)%INF + INF;
          	ans %= INF;
        }
    }
    f(i,0,m){
        if(max(dist[0][aa[i]],dist[1][bb[i]]) < path / 2.0 && dist[0][aa[i]] + dist[1][bb[i]] + ww[i] == path){
            ll num = (cou[0][aa[i]] * cou[1][bb[i]]) % INF
            ans -= (num * num)%INF + INF;
          	ans %= INF;
        }
        swap(aa[i],bb[i]);
    }
    f(i,0,m){
        if(max(dist[0][aa[i]],dist[1][bb[i]]) < path / 2.0 && dist[0][aa[i]] + dist[1][bb[i]] + ww[i] == path){
          	ll num = (cou[0][aa[i]] * cou[1][bb[i]]) % INF
            ans -= (num * num)%INF + INF;
          	ans %= INF;
        }
    }
    ans %= MOD;
    pl(ans);
}


Compiler output:
a.cc: In function 'void dfs(ll)':
a.cc:45:16: error: reference to 'visit' is ambiguous
   45 | void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
      |                ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:30:5: note:                 'std::vector<long long int> visit'
   30 | vll visit,dist[2],taken,cou[2];
      |     ^~~~~
a.cc:45:52: error: reference to 'visit' is ambiguous
   45 | void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
      |                                                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:30:5: note:                 'std::vector<long long int> visit'
   30 | vll visit,dist[2],taken,cou[2];
      |     ^~~~~
a.cc: In function 'void bfs(ll)':
a.cc:46:16: error: reference to 'visit' is ambiguous
   46 | void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
      |                ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:30:5: note:                 'std::vector<long long int> visit'
   30 | vll visit,dist[2],taken,cou[2];
      |     ^~~~~
a.cc:46:122: error: reference to 'visit' is ambiguous
   46 | void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
      |                                                                                                                          ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:30:5: note:                 'std::vector<long long int> visit'
   30 | vll visit,dist[2],taken,cou[2];
      |     ^~~~~
a.cc:46:132: error: reference to 'visit' is ambiguous
   46 | void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
      |                                                                                                                                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:30:5: note:                 'std::vector<long long int> visit'
   30 | vll visit,dist[2],taken,cou[2];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:91:13: error: expected ',' or ';' before 'ans'
   91 |             ans -= (num * num)%INF + INF;
      |             ^~~
a.cc:98:13: error: expected ',' or ';' before 'ans'
   98 |             ans -= (num * num)%INF + INF;
      |             ^~~
a.cc:106:13: error: expected ',' or ';' before 'ans'
  106 |             ans -= (num * num)%INF + INF;
      |             ^~~