/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());
#include<vector>

constexpr ll mod17 = 1e9+7;
constexpr ll mod19 = 1e9+9;
constexpr ll mod9 = 998244353;
ll mod = mod17;

// Mod int library
unordered_map<ll, ll> minvmap;
ll minv(ll a, ll m) {
  auto k = a; auto p = minvmap[a]; if (p != 0) return p;
  ll b = m, u = 1, v = 0;
  while (b) { ll t = a/b; swap(a -= t*b, b); swap(u -= t*v, v); }
  p = (u%m+m)%m; minvmap[k] = p; return p;
}

struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint& operator/=(const mint& a){ (x*=minv(a.x, mod))%=mod; return *this; }
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};

template<typename T>
T mod_pow(T a, ll x) {
  T res = 1;
  while(x > 0) {
    if (x & 1) res *= a;
    a *= a; x >>= 1;
  }
  return res;
}

class combination {
    // factorial
    public: std::vector<mint> fact;
    public: std::vector<mint> inv;

    combination(int n) {
      fact.resize(n + 1);
      inv.resize(n + 1);
      fact[0] = 1;
      for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i;
      }
      inv[n] = mint(1) / fact[n];
      for (int i = n - 1; i >= 0; i--) {
        inv[i] = inv[i + 1] * (i + 1);
      }
    }

    // nCr
    public: mint get(int n, int r) {
      if (n < r || n < 0 || r < 0) return 0;
      return fact[n]*inv[r]*inv[n-r];
    }
    // nPr
    public: mint p(int n, int r) {
      if (n < r || n < 0) return 0;
      return fact[n]*inv[n-r];
    }
};

class EAvoidingCollision {
public:

    vector<P> graph[100005];
    vector<ll> costs, costt;
    vector<mint> cnts, cntt;

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m; cin >> n >> m;
      int s, t; cin >> s >> t;
      costs.resize(n+1, LLONG_MAX/2);
      costt.resize(n+1, LLONG_MAX/2);
      cnts.resize(n+1);
      cntt.resize(n+1);
      vector<P> vec(m);
      vector<ll> cost(m);

      rep(i, m) {
        ll u, v, d; cin >> u >> v >> d;
        graph[u].emplace_back(v, d);
        graph[v].emplace_back(u, d);
        vec[i].first = u;
        vec[i].second = v;
        cost[i] = d;
      }

      priority_queue<P, vector<P>, greater<>> que;

      que.emplace(0, s);
      costs[s] = 0;
      cnts[s] = 1;
      while(!que.empty()) {
        // q -> r
        auto p = que.top(); que.pop();
        auto c = p.first;
        auto q = p.second;
        if (c > costs[q]) continue;
        for(auto e: graph[q]) {
          auto r = e.first;
          auto d = e.second;
          if (costs[r] > c + d) {
            costs[r] = c + d;
            cnts[r] = cnts[q];
            que.emplace(c+d, r);
          } else if (costs[r] == c + d) {
            cnts[r] += cnts[q];
          }
        }
      }

      que.emplace(0, t);
      costt[t] = 0;
      cntt[t] = 1;
      while(!que.empty()) {
        // q -> r
        auto p = que.top(); que.pop();
        auto c = p.first;
        auto q = p.second;
        if (c > costt[q]) continue;
        for(auto e: graph[q]) {
          auto r = e.first;
          auto d = e.second;
          if (costt[r] > c + d) {
            costt[r] = c + d;
            cntt[r] = cntt[q];
            que.emplace(c+d, r);
          } else if (costt[r] == c + d) {
            cntt[r] += cntt[q];
          }
        }
      }

      mint all = cnts[t]*cnts[t];

      mint point = 0;
      for(int i=1; i<=n; i++) {
        if (i==s || i==t) continue;
        if (costs[i] + costs[i] == costs[t]) {
          point += cnts[i]*cnts[i]*cntt[i]*cntt[i];
        }
      }

      mint edge = 0;
      rep(i, m) {
        int u = vec[i].first;
        int v = vec[i].second;
        int c = cost[i];
        if (costs[u] + costt[v] + c == costs[t]) {
          if (costs[u] + costs[u] < costs[t] && costt[v] + costt[v] < costs[t]) {
            edge += cnts[u]*cnts[u]*cntt[v]*cntt[v];
          }
        }
        if (costs[v] + costt[u] + c == costs[t]) {
          if (costs[v] + costs[v] < costs[t] && costt[u] + costt[u] < costs[t]) {
            edge += cnts[v]*cnts[v]*cntt[u]*cntt[u];
          }
        }
      }

      cout << (all - point - edge).x << endl;
    }
};

signed main() {
  EAvoidingCollision solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 22896