#include <bits/stdc++.h>
using namespace std;
const int maxn = 201010 * 40;
const int mod = 1e9 + 7;
const int N = 201010;
int n, m, s, t;
vector<pair<int, int> > G[101010];
int cnt = 1, rt[505050], hsh[maxn], pw2[505050];
int ls[maxn], rs[maxn], siz[maxn];
void upd(int p, int l, int r) {
  int mid = (l + r) >> 1;
  int len = mid - l + 1;
  hsh[p] = (hsh[ls[p]] + 1ll * pw2[len] * hsh[rs[p]] % mod) % mod;
  siz[p] = siz[ls[p]] + siz[rs[p]];
}
void ins1(int p, int &q, int l, int r, int ql, int qr) {
  q = ++cnt;
  ls[q] = ls[p];
  rs[q] = rs[p];
  siz[q] = siz[p];
  hsh[q] = hsh[p];
  if (ql <= l && r <= qr) {
    q = 0;
    return;
  }
  if (q == 0) {
    q = ++cnt;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) {
    ins1(ls[p], ls[q], l, mid, ql, qr);
  }
  if (mid < qr) {
    ins1(rs[p], rs[q], mid + 1, r, ql, qr);
  }
  upd(q, l, r);
}
void ins2(int p, int &q, int l, int r, int pos) {
  if (q == 0) {
    q = ++cnt;
  } else {
    q = ++cnt;
    ls[q] = ls[p];
    rs[q] = rs[p];
    siz[q] = siz[p];
    hsh[q] = hsh[p];
  }
  if (l == r) {
    hsh[q] = 1;
    siz[q] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid) {
    ins2(ls[p], ls[q], l, mid, pos);
  } else {
    ins2(rs[p], rs[q], mid + 1, r, pos);
  }
  upd(q, l, r);
}
int query(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    return siz[p];
  }
  int mid = (l + r) >> 1;
  int ret = 0;
  if (ql <= mid) ret += query(ls[p], l, mid, ql, qr);
  if (mid < qr) ret += query(rs[p], mid + 1, r, ql, qr);
  return ret;
}
int add(int r, int x) {
  int l = x, rr = N, pos = -1;
  while (l <= rr) {
    int mid = (l + rr) >> 1;
    if (query(r, 0, N, x, mid) == mid - x + 1) {
      pos = mid;
      l = mid + 1;
    } else {
      rr = mid - 1;
    }
  }
  int se = r;
  if (pos != -1) {
    se = ++cnt;
    ins1(r, se, 0, N, x, pos);
  } else {
    pos = x - 1;
  }
  int th = ++cnt;
  ins2(se, th, 0, N, pos + 1);
  return th;
}
int Small(int p, int q, int l, int r) {
  if (l == r) {
    return hsh[p] < hsh[q];
  }
  int mid = (l + r) >> 1;
  if (hsh[rs[p]] == hsh[rs[q]]) {
    return Small(ls[p], ls[q], l, mid);
  } else {
    return Small(rs[p], rs[q], mid + 1, r);
  }
}
int small(int p, int q) { return Small(p, q, 0, N); }
struct Nd {
  int u, r;
  bool operator<(const Nd &x) const { return !small(r, x.r); }
};
priority_queue<Nd> Q;
int dis[101010], pre[101010];
int sta[101010], top;
void dij() {
  for (int i = 1; i <= n; i++) {
    pre[i] = 1e9;
  }
  while (!Q.empty()) Q.pop();
  dis[s] = 0;
  Q.push({s, dis[s]});
  while (!Q.empty()) {
    Nd tmp = Q.top();
    Q.pop();
    int u = tmp.u, r = tmp.r;
    if (dis[u] != 0 && small(dis[u], r)) {
      continue;
    }
    for (auto t : G[u]) {
      int v = t.first, x = t.second;
      int nr = add(dis[u], x);
      if (dis[v] == 0 or small(nr, dis[v])) {
        dis[v] = nr;
        pre[v] = u;
        Q.push({v, dis[v]});
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, x;
    scanf("%d %d %d", &u, &v, &x);
    G[u].push_back({v, x});
    G[v].push_back({u, x});
  }
  scanf("%d %d", &s, &t);
  if (s == t) {
    puts("0");
    puts("1");
    printf("%d\n", s);
    return 0;
  }
  pw2[0] = 1;
  for (int i = 1; i <= N; i++) {
    pw2[i] = 1ll * pw2[i - 1] * 2 % mod;
  }
  dij();
  if (hsh[dis[t]] == 0) {
    puts("-1");
    return 0;
  }
  printf("%d\n", hsh[dis[t]]);
  while (t != s) {
    sta[++top] = t;
    t = pre[t];
  }
  sta[++top] = s;
  printf("%d\n", top);
  while (top) printf("%d ", sta[top--]);
  return 0;
}
