464_E. The Classic Problem

You are given a weighted undirected graph on n vertices and m edges. Find the shortest path from vertex s to vertex t or else state that such path doesn't exist.

Input

The first line of the input contains two space-separated integers — n and m (1 ≤ n ≤ 105; 0 ≤ m ≤ 105).

Next m lines contain the description of the graph edges. The i-th line contains three space-separated integers — ui, vi, xi (1 ≤ ui, vi ≤ n; 0 ≤ xi ≤ 105). That means that vertices with numbers ui and vi are connected by edge of length 2xi (2 to the power of xi).

The last line contains two space-separated integers — the numbers of vertices s and t.

The vertices are numbered from 1 to n. The graph contains no multiple edges and self-loops.

Output

In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109 + 7) if the path exists, and -1 if the path doesn't exist.

If the path exists print in the second line integer k — the number of vertices in the shortest path from vertex s to vertex t; in the third line print k space-separated integers — the vertices of the shortest path in the visiting order. The first vertex should be vertex s, the last vertex should be vertex t. If there are multiple shortest paths, print any of them.

Examples

Input

4 4
1 4 2
1 2 0
2 3 0
3 4 0
1 4


Output

3
4
1 2 3 4 


Input

4 3
1 2 4
2 3 5
3 4 6
1 4


Output

112
4
1 2 3 4 


Input

4 2
1 2 0
3 4 1
1 4


Output

-1

Note

A path from vertex s to vertex t is a sequence v0, ..., vk, such that v0 = s, vk = t, and for any i from 0 to k - 1 vertices vi and vi + 1 are connected by an edge. 

The length of the path is the sum of weights of edges between vi and vi + 1 for all i from 0 to k - 1. 

The shortest path from s to t is the path which length is minimum among all possible paths from s to t.

Example input:
4 3
1 2 4
2 3 5
3 4 6
1 4

4 4
1 4 2
1 2 0
2 3 0
3 4 0
1 4

4 2
1 2 0
3 4 1
1 4


Example output:
112
4
1 2 3 4 
3
4
1 2 3 4 
-1


Tags: data structures
graphs
shortest paths
Difficulty rating: 3000

Solution:
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, maxn = 2e5 + 5, mod = 1e9 + 7;
int n, m, lim;
struct edges {
  int to, nxt, v;
} ed[maxn << 1];
int head[maxn], ecnt = 0;
int p2[maxn], curs = 0, s, t;
int pre[maxn], rt[maxn];
struct segm {
  int ls, rs, sum;
} se[maxn << 5];
void add(int x, int y, int z) {
  ed[++ecnt].to = y;
  ed[ecnt].nxt = head[x];
  ed[ecnt].v = z;
  head[x] = ecnt;
}
int cmp(int u, int v, int l, int r) {
  if (l == r) return se[u].sum > se[v].sum;
  int mid = l + r >> 1;
  if (se[se[u].rs].sum == se[se[v].rs].sum)
    return cmp(se[u].ls, se[v].ls, l, mid);
  else
    return cmp(se[u].rs, se[v].rs, mid + 1, r);
}
struct node {
  int x, rt;
  bool operator<(node b) const { return cmp(rt, b.rt, 0, lim); }
};
int update(int lst, int &now, int l, int r, int k) {
  now = ++curs;
  se[now] = se[lst];
  if (l == r) {
    se[now].sum = se[lst].sum ^ 1;
    return se[lst].sum;
  }
  int mid = l + r >> 1, res;
  if (k > mid)
    res = update(se[lst].rs, se[now].rs, mid + 1, r, k);
  else {
    res = update(se[lst].ls, se[now].ls, l, mid, k);
    if (res) res = update(se[lst].rs, se[now].rs, mid + 1, r, k);
  }
  se[now].sum =
      (1ll * se[se[now].rs].sum * p2[mid - l + 1] + se[se[now].ls].sum) % mod;
  return res;
}
void dfs(int u, int dep) {
  if (u == s) {
    printf("%d\n%d ", dep, u);
    return;
  }
  dfs(pre[u], dep + 1);
  printf("%d ", u);
}
void print(int t) {
  printf("%d\n", se[rt[t]].sum);
  dfs(t, 1);
  puts("");
  exit(0);
}
int main() {
  memset(head, -1, sizeof head);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
    lim = max(lim, z);
  }
  lim += 100;
  p2[0] = 1;
  for (int i = 1; i <= lim; i++) p2[i] = 2ll * p2[i - 1] % mod;
  scanf("%d%d", &s, &t);
  priority_queue<node> pq;
  pq.push((node){s, rt[s]});
  while (!pq.empty()) {
    node tp = pq.top();
    pq.pop();
    if (tp.rt != rt[tp.x]) continue;
    if (tp.x == t) print(t);
    for (int i = head[tp.x]; i != -1; i = ed[i].nxt) {
      int u = ed[i].to, currt;
      update(tp.rt, currt, 0, lim, ed[i].v);
      if (!rt[u] || cmp(rt[u], currt, 0, lim))
        rt[u] = currt, pq.push((node){u, rt[u]}), pre[u] = tp.x;
    }
  }
  puts("-1");
  return 0;
}