Language: C++

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

struct edge
{
    int v,w,nxt;
}e[400050];

long long dist1[100050],cnt[100050],dist2[100050];
long long tot[100050],tot2[100050];
int head[100050],ecnt;
int S,T,N,M;
int inq[100050];

const int mod = 1000000007;

void adde(int u,int v,int w)
{
    e[++ecnt].v = v;
    e[ecnt].w = w;
    e[ecnt].nxt = head[u];
    head[u] = ecnt;
}

void spfa1()
{
    memset(dist1,0x3f3f3f3f,sizeof(dist1));
    inq[S] = true;
    dist1[S] = 0;
    cnt[S] = 1;
    queue<int> que;
    que.push(S);
    while(!que.empty())
    {
        int u = que.front();
        tot[u] += cnt[u];
        que.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].v;
            if(dist1[v] == dist1[u] + e[i].w)
            {
                cnt[v] += cnt[u];
                cnt[v] %= 1000000007;
                if(!inq[v])
                {
                    inq[v] = true;
                    que.push(v);
                }
            }
            if(dist1[v] > dist1[u] + e[i].w)
            {
                cnt[v] = cnt[u];
                dist1[v] = dist1[u] + e[i].w;
                if(!inq[v])
                {
                    inq[v] = true;
                    que.push(v);
                }
            }
        }
        cnt[u] = 0;
        inq[u] = false;
    }
}

int vis[100050];
bool able[100050];

void spfa2()
{
    memset(dist2,0x3f3f3f3f,sizeof(dist2));
    inq[T] = true;
    dist2[T] = 0;
    queue<int> que;
    que.push(T);
    cnt[T] = 1;
    while(!que.empty())
    {
        int u = que.front();
        tot2[u] += cnt[u];
        que.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].v;
            if(dist2[v] == dist2[u] + e[i].w)
            {
                cnt[v] += cnt[u];
                if(!inq[v])
                {
                    inq[v] = true;
                    que.push(v);
                }
            }
            if(dist2[v] > dist2[u] + e[i].w)
            {
                dist2[v] = dist2[u] + e[i].w;
                cnt[v] = cnt[u];
                if(!inq[v])
                {
                    inq[v] = true;
                    que.push(v);
                }
            }
        }
        inq[u] = false;
        cnt[u] = 0;
    }
}

long long dist[100050];
bool mark[100050];
bool mk2[100050];

long long qpow(long long base,int tms)
{
    long long tmp = 1;
    while(tms)
    {
        if(tms & 1)
            tmp = tmp * base % mod;
        base = base * base % mod;
        tms >>= 1;
    }
    return tmp;
}

int main()
{
    scanf("%d%d%d%d",&N,&M,&S,&T);
    int u,v,w;
    for(int i = 1;i <= M; ++ i)
    {
        scanf("%d%d%d",&u,&v,&w);
        adde(u,v,w);
        adde(v,u,w);
    }
    spfa1();
    spfa2();
    int cnt = 0;
    long long ans = 0;
    long long totx = tot[T];
    memset(dist,0x3f3f3f3f,sizeof(dist));
    queue<int> que;
    inq[S] = 1;
    que.push(S);
    dist[S] = 0;
    while(!que.empty())
    {
        int u = que.front();
        que.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].v;
            if(dist[v] > dist[u] + e[i].w)
            {
                dist[v] = dist[u] + e[i].w;
                if(dist1[T] % 2 == 0)
                {
                    if(dist[v] == dist1[T] / 2)
                        mk2[v] = true;
                    else
                        mk2[v] = false;
                    if(dist[v] > dist1[T] / 2 && dist[u] < dist1[T] / 2)
                        mark[v] = true;
                    else
                        mark[v] = false;
                }
                else
                {
                    if(dist[v] >= dist1[T] / 2 + 1 && dist[u] < dist1[T] / 2 + 1)
                        mark[v] = true;
                    else
                        mark[v] = false;
                }
                if(!inq[v])
                {
                    inq[v] = 1;
                    que.push(v);
                }
            }
        }
        inq[u] = false;
    }
    long long ans2 = 1;
    for(int i = 1;i <= N; ++ i)
    {
        if(mark[i])
        {
            ans += (long long)tot[i] * (tot[i] - 1) % mod * qpow(2,1000000005) % mod * tot2[i] % mod;
            ans %= mod;
            ans2 *= tot[i] * tot2[i] % modi
            ans2 %= mod;
        }
        else if(mk2[i])
        {
            ans2 *= tot[i] * tot2[i];
            ans2 %= mod;
        }
    }
    printf("%lld\n",(ans2 + ans) * 2 % mod);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:197:40: error: 'modi' was not declared in this scope; did you mean 'mod'?
  197 |             ans2 *= tot[i] * tot2[i] % modi
      |                                        ^~~~
      |                                        mod