let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)
let ( *^ ) x y = (x * y) mod m

module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n%d %d\n" @@ fun n m s t ->
  let uvds = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun u v d -> u - 1, v - 1, d in
  let es = Array.make n [] in
  Array.iter (fun (u, v, d) ->
    es.(u) <- (v, d) :: es.(u);
    es.(v) <- (u, d) :: es.(v)) uvds;
  let rec dijkstra d p q =
    match IntMap.min_binding q with
    | exception Not_found -> ()
    | (w, us) ->
        dijkstra d p @@ List.fold_left (fun q u ->
          if d.(u) < w
          then q
          else List.fold_left (fun q (v, c) ->
            match compare d.(v) (w + c) with
            | -1 -> q
            | 0  -> p.(v) <- p.(u) +^ p.(v); q
            | 1  -> p.(v) <- p.(u); d.(v) <- w + c; IntMap.add (w + c) (v :: try IntMap.find (w + c) q with Not_found -> []) q)
          q es.(u)) (IntMap.remove w q) us in
  let [(dt, pt); (da, pa)] = List.map (fun s ->
    let d = Array.make n max_int in
    let p = Array.make n 0 in
    d.(s) <- 0;
    p.(s) <- 1;
    dijkstra d p (IntMap.singleton 0 [s]);
    (d, p)) [s - 1; t - 1] in
  Printf.printf "%d\n" @@
  Array.fold_right (fun v acc ->
    if dt.(v) = da.(v) then acc -^ pt.(v) *^ pa.(v) *^ pt.(v) *^ pa.(v) else acc)
  (Array.init n @@ fun v -> v) @@
  Array.fold_left (fun acc (u, v, d) ->
    if
      dt.(t - 1) < d + min (dt.(u) + da.(v)) (da.(u) + dt.(v)) ||
      max dt.(u) dt.(v) <= min da.(u) da.(v) ||
      max da.(u) da.(v) <= min dt.(u) dt.(v)
    then acc
    else
      if dt.(u) < dt.(v)
      then acc -^ pt.(u) *^ pa.(v) *^ pt.(u) *^ pa.(v)
      else acc -^ pa.(u) *^ pt.(v) *^ pa.(u) *^ pt.(v)) (pt.(t - 1) *^ pa.(s - 1)) uvds
