#include <bits/stdc++.h>
int MOD = 1e9 + 7;
long long MODD = 10877777;
long long INF = 1e9 + 11;
int NN, MM;
int AA, BB, CC;
std::vector<std::pair<int, int>> G[100000];
const int nnn = 1 << 17;
const long long PP = 100000007;
std::vector<long long> pw;
std::vector<int> ptwo;
struct Node {
  int cone;
  int lll, rrr;
  long long hash;
  Node() { cone = 0, hash = 0; }
  Node(int cone, int lll, int rrr, long long hash)
      : cone(cone), lll(lll), rrr(rrr), hash(hash) {}
};
Node nd[5739500];
int node_ptr;
void set_0() {
  node_ptr = nnn * 2 - 1;
  for (int i = 0; i < nnn - 1; ++i) {
    nd[i] = Node(0, i * 2 + 1, i * 2 + 2, 0);
  }
  for (int i = nnn; i < nnn + nnn - 1; ++i) {
    nd[i] = Node(0, -1, -1, 0);
  }
}
int search0(int aa, int bb, int kk, int lll, int rrr) {
  if (rrr <= aa || bb <= lll) return INF;
  if (nd[kk].cone == -1) return std::max(lll, aa);
  if (nd[kk].cone == rrr - lll) return INF;
  if (lll + 1 == rrr) {
    if (nd[kk].cone <= 0) {
      return lll;
    } else {
      return INF;
    }
  }
  int pp = search0(aa, bb, nd[kk].lll, lll, (lll + rrr) / 2);
  if (pp < INF) return pp;
  return search0(aa, bb, nd[kk].rrr, (lll + rrr) / 2, rrr);
}
int set0(int aa, int bb, int kk, int lll, int rrr) {
  if (rrr <= aa || bb <= lll) return kk;
  if (nd[kk].cone == -1) return kk;
  if (aa <= lll && rrr <= bb) {
    int xxx = node_ptr++;
    nd[xxx].cone = -1;
    nd[xxx].hash = 0;
    nd[xxx].lll = nd[kk].lll, nd[xxx].rrr = nd[kk].rrr;
    return xxx;
  }
  int pone = set0(aa, bb, nd[kk].lll, lll, (lll + rrr) / 2);
  int ptwo = set0(aa, bb, nd[kk].rrr, (lll + rrr) / 2, rrr);
  int xxx = node_ptr++;
  nd[xxx].cone = std::max(0, nd[pone].cone) + std::max(0, nd[ptwo].cone);
  nd[xxx].lll = pone, nd[xxx].rrr = ptwo;
  nd[xxx].hash = nd[pone].hash * pw[(rrr - lll) / 2] + nd[ptwo].hash;
  return xxx;
}
int change(int aa, int bb, int kk, int lll, int rrr) {
  if (rrr <= aa || bb <= lll) return kk;
  if (aa <= lll && rrr <= bb) {
    int xxx = node_ptr++;
    nd[xxx].cone = 1;
    nd[xxx].hash = 1;
    nd[xxx].lll = -1, nd[xxx].rrr = -1;
    return xxx;
  }
  if (nd[kk].cone == -1) {
    nd[kk].lll = set0(lll, (lll + rrr) / 2, nd[kk].lll, lll, (lll + rrr) / 2);
    nd[kk].rrr = set0((lll + rrr) / 2, rrr, nd[kk].rrr, (lll + rrr) / 2, rrr);
    nd[kk].cone = 0;
  }
  int pone = change(aa, bb, nd[kk].lll, lll, (lll + rrr) / 2);
  int ptwo = change(aa, bb, nd[kk].rrr, (lll + rrr) / 2, rrr);
  int xxx = node_ptr++;
  nd[xxx].cone = std::max(0, nd[pone].cone) + std::max(0, nd[ptwo].cone);
  nd[xxx].lll = pone, nd[xxx].rrr = ptwo;
  nd[xxx].hash = (nd[pone].hash * pw[(rrr - lll) / 2] + nd[ptwo].hash) % MODD;
  return xxx;
}
int seg_add(int id, int kk) {
  int pos = search0(kk, nnn, id, 0, nnn);
  if (kk != pos) id = set0(kk, pos, id, 0, nnn);
  return change(pos, pos + 1, id, 0, nnn);
}
int cmp(int sone, int stwo, int ww) {
  if (nd[sone].hash == nd[stwo].hash) return 0;
  if (nd[sone].cone == -1) return 1;
  if (nd[stwo].cone == -1) return -1;
  if (ww == 1) {
    if (std::max(0, nd[sone].cone) < std::max(0, nd[stwo].cone)) return 1;
    if (std::max(0, nd[sone].cone) > std::max(0, nd[stwo].cone)) return -1;
  }
  int tt = cmp(nd[sone].rrr, nd[stwo].rrr, ww / 2);
  if (tt) return tt;
  return cmp(nd[sone].lll, nd[stwo].lll, ww / 2);
}
int seg_cmp(int aa, int bb) {
  if (aa == bb) return 0;
  if (aa == -1) return -1;
  if (bb == -1) return 1;
  return cmp(aa, bb, nnn);
}
int getval(int id, int lll, int rrr) {
  if (nd[id].cone == -1) return 0;
  if (lll + 1 == rrr) return nd[id].cone;
  return (static_cast<long long>(getval(nd[id].rrr, (lll + rrr) / 2, rrr)) *
              ptwo[(rrr - lll) / 2] +
          getval(nd[id].lll, lll, (lll + rrr) / 2)) %
         MOD;
}
struct Query {
  int vv, id;
  Query() {}
  Query(int vv, int id) : vv(vv), id(id) {}
  bool operator<(const Query q) const { return seg_cmp(q.id, id) == 1; }
  bool operator>(const Query q) const { return seg_cmp(q.id, id) == -1; }
};
int dd[100000];
int prev[100000];
int sS, sT;
int main() {
  scanf("%d%d", &NN, &MM);
  pw.push_back(1ll);
  for (int i = 1; i < nnn + 2; ++i) {
    pw.push_back(pw[i - 1] * PP % MODD);
  }
  ptwo.push_back(1);
  for (int i = 1; i < nnn + 2; ++i) {
    ptwo.push_back((ptwo[i - 1] * 2) % MOD);
  }
  while (MM--) {
    scanf("%d%d%d", &AA, &BB, &CC), AA--, BB--;
    G[AA].push_back(std::make_pair(CC, BB));
    G[BB].push_back(std::make_pair(CC, AA));
  }
  scanf("%d%d", &sS, &sT);
  sS--;
  sT--;
  for (int i = 0; i < NN; ++i) {
    dd[i] = -1;
  }
  dd[sS] = 0;
  std::memset(prev, -1, sizeof(prev));
  set_0();
  std::priority_queue<Query> q;
  q.push(Query(sS, 0));
  while (!q.empty()) {
    int vr = q.top().vv, c = q.top().id;
    q.pop();
    if (dd[vr] != c) continue;
    if (vr == sT) break;
    for (int i = 0; i < G[vr].size(); ++i) {
      int tmp = seg_add(c, G[vr][i].first);
      if (Query(G[vr][i].second, tmp) >
          Query(G[vr][i].second, dd[G[vr][i].second])) {
        dd[G[vr][i].second] = tmp;
        q.push(Query(G[vr][i].second, tmp));
        prev[G[vr][i].second] = vr;
      }
    }
  }
  if (dd[sT] == -1) return puts("-1"), 0;
  printf("%d\n", getval(dd[sT], 0, nnn));
  std::vector<int> vv;
  while (sT != sS) vv.push_back(sT + 1), sT = prev[sT];
  vv.push_back(sS + 1);
  std::reverse(vv.begin(), vv.end());
  std::cout << vv.size() << std::endl;
  for (int vvv : vv) {
    std::cout << vvv << " ";
  }
}
