#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
int hashv[100100 * 80];
int ch[100100 * 80][2], cnt[100100 * 80];
int tot;
int p2[100100];
int rt[100100];
int fst[100100], cost[5000010], nxt[5000010], vv[5000010], e;
long long ans;
void init() {
  e = 0;
  memset(fst, -1, sizeof fst);
  p2[0] = 1;
  for (int i = 1; i < 100100; i++) {
    p2[i] = 2LL * p2[i - 1] % 1000000007;
  }
}
void add(int u, int v, int c) {
  vv[e] = v, nxt[e] = fst[u], cost[e] = c, fst[u] = e++;
  vv[e] = u, nxt[e] = fst[v], cost[e] = c, fst[v] = e++;
}
void up(int rt, int ll, int rr) {
  cnt[rt] = cnt[ch[rt][0]] + cnt[ch[rt][1]];
  hashv[rt] =
      (1LL * hashv[ch[rt][0]] * p2[rr - ((ll + rr) >> 1)] + hashv[ch[rt][1]]) %
      1000000007;
}
int update(int rt, int x, int v, int ll, int rr) {
  int k = ++tot;
  ch[k][0] = ch[rt][0];
  ch[k][1] = ch[rt][1];
  cnt[k] = cnt[rt] + v;
  if (ll == rr) {
    hashv[k] = v;
    return k;
  }
  if (x <= ((ll + rr) >> 1))
    ch[k][0] = update(ch[rt][0], x, v, ll, ((ll + rr) >> 1));
  else
    ch[k][1] = update(ch[rt][1], x, v, ((ll + rr) >> 1) + 1, rr);
  up(k, ll, rr);
  return k;
}
int getfirstone(int rt, int x, int ll, int rr) {
  if (cnt[rt] == rr - ll + 1) return -1;
  if (ll == rr) {
    if (cnt[rt])
      return -1;
    else
      return ll;
  }
  if (x > ((ll + rr) >> 1))
    return getfirstone(ch[rt][1], x, ((ll + rr) >> 1) + 1, rr);
  else if (x == ll) {
    if (cnt[ch[rt][0]] == ((ll + rr) >> 1) - ll + 1)
      return getfirstone(ch[rt][1], ((ll + rr) >> 1) + 1, ((ll + rr) >> 1) + 1,
                         rr);
    else
      return getfirstone(ch[rt][0], x, ll, ((ll + rr) >> 1));
  }
  int res = getfirstone(ch[rt][0], x, ll, ((ll + rr) >> 1));
  if (res == -1)
    res =
        getfirstone(ch[rt][1], ((ll + rr) >> 1) + 1, ((ll + rr) >> 1) + 1, rr);
  return res;
}
int setzero(int rt, int l, int r, int ll, int rr) {
  if (l == ll && r == rr) return 0;
  int k = ++tot;
  ch[k][0] = ch[rt][0];
  ch[k][1] = ch[rt][1];
  if (r <= ((ll + rr) >> 1))
    ch[k][0] = setzero(ch[rt][0], l, r, ll, ((ll + rr) >> 1));
  else if (l > ((ll + rr) >> 1))
    ch[k][1] = setzero(ch[rt][1], l, r, ((ll + rr) >> 1) + 1, rr);
  else
    ch[k][0] = setzero(ch[rt][0], l, ((ll + rr) >> 1), ll, ((ll + rr) >> 1)),
    ch[k][1] =
        setzero(ch[rt][1], ((ll + rr) >> 1) + 1, r, ((ll + rr) >> 1) + 1, rr);
  up(k, ll, rr);
  return k;
}
bool cmp(int rt1, int rt2, int ll, int rr) {
  if (hashv[rt1] == hashv[rt2]) return 0;
  if (ll == rr) {
    return cnt[rt1] < cnt[rt2];
  }
  if (hashv[ch[rt1][1]] != hashv[ch[rt2][1]])
    return cmp(ch[rt1][1], ch[rt2][1], ((ll + rr) >> 1) + 1, rr);
  return cmp(ch[rt1][0], ch[rt2][0], ll, ((ll + rr) >> 1));
}
void dfs(int rt, int ll, int rr) {
  if (ll == rr) {
    if (cnt[rt])
      ans = ans * 2 + 1;
    else
      ans *= 2;
    ans %= 1000000007;
    return;
  }
  dfs(ch[rt][1], ((ll + rr) >> 1) + 1, rr);
  dfs(ch[rt][0], ll, ((ll + rr) >> 1));
}
struct node {
  int u, rt;
  node() {}
  node(int _u, int _rt) : u(_u), rt(_rt) {}
  bool operator<(const node& x) const { return cmp(x.rt, rt, 0, 100100 - 1); }
};
int s, t;
int n, m, pre[100100];
void spfa() {
  priority_queue<node> q;
  q.push(node(s, rt[s]));
  for (int i = 1; i <= n; i++)
    if (i != s) rt[i] = update(0, 100100 - 1, 1, 0, 100100 - 1);
  while (!q.empty()) {
    int u = q.top().u;
    int root = q.top().rt;
    q.pop();
    if (rt[u] != root) continue;
    for (int i = fst[u]; ~i; i = nxt[i]) {
      int v = vv[i], c = cost[i];
      int p = getfirstone(rt[u], c, 0, 100100 - 1);
      int t = rt[u];
      if (p > c) t = setzero(rt[u], c, p - 1, 0, 100100 - 1);
      t = update(t, p, 1, 0, 100100 - 1);
      if (cmp(t, rt[v], 0, 100100 - 1)) {
        rt[v] = t;
        pre[v] = u;
        q.push(node(v, rt[v]));
      }
    }
  }
}
void solve() {
  spfa();
  if (pre[t] == 0) {
    puts("-1");
    return;
  }
  ans = 0;
  dfs(rt[t], 0, 100100 - 1);
  vector<int> ans1;
  ans1.push_back(t);
  while (pre[t]) {
    t = pre[t];
    ans1.push_back(t);
  }
  int ss = (int)ans1.size();
  printf("%lld\n%d\n", ans, ss);
  for (int i = ss - 1; i >= 0; i--) {
    printf("%d%c", ans1[i], i == 0 ? '\n' : ' ');
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    add(u, v, c);
  }
  scanf("%d%d", &s, &t);
  if (s == t) {
    puts("0");
    puts("1");
    printf("%d\n", s);
    return 0;
  }
  solve();
}
