Under construction

Still being built. Things may change

Note Fragments

Time limit2sMemory limit1024 MB

Summary
Find a walk from vertex 1 to vertex N that visits every vertex holding a note fragment and arrives no later than the shortest 1-to-N distance, or report -1.
Level

Medium7 of 10

Topics
Shortest path, Graph, Dynamic programming
Solved
No attempts yet

Problem

A running race is held in a world of vertices numbered 1 through NN, connected by MM bidirectional edges. The race starts at vertex 11. The first person to reach vertex NN and log in to their account wins. If several people log in first at the same time, all of them win.

Participant lobo_prix has a poor memory and writes the password on a notebook. The malicious participant jhnah917 tore up the notebook and hid the pieces around the world. lobo_prix cannot remember the password, so lobo_prix must collect every note fragment and then go to vertex NN. jhnah917 only travels along shortest paths to vertex NN.

The time to pick up a fragment and the time to log in are negligible, so assume they are 00. All participants move at the same speed. Is there a path that lets lobo_prix win?

Input

The first line contains the number of vertices NN and the number of edges MM, separated by a space. (2≤N≤200 000, N−1≤M≤200 0002\leq N \leq 200\,000,\ N-1 \leq M \leq 200\,000)

Each of the next MM lines contains the two vertices u_i,v_iu\_i, v\_i connected by the ii-th edge and its length w_iw\_i. (1≤u_i,v_i≤N, 1≤w_i≤109, u_i≠v_i, w_i1\leq u\_i,v\_i\leq N,\ 1 \leq w\_i \leq 10^9,\ u\_i \neq v\_i,\ w\_i is an integer)

The next line contains NN integers A_1,A_2,⋯ ,A_NA\_1, A\_2, \cdots, A\_N. If vertex ii has a note fragment, A_i=1A\_i=1. Otherwise, A_i=0A\_i=0.

No pair of vertices is connected by more than one edge. The graph is given such that vertex NN can be reached from vertex 11.

Output

If there is no path that lets lobo_prix win, print −1-1.

If there is such a path, print the number of visited vertices on the first line. On the next line, print the visited vertices in the order they are visited, separated by spaces.

If several paths are possible, print any one of them.

Examples3

  1. Example 1

    Input
    4 4
    1 2 1
    2 4 1
    1 3 1
    3 4 1
    1 1 0 1
    
    Expected output
    3
    1 2 4
    
  2. Example 2

    Input
    4 4
    1 2 2
    2 4 1
    1 3 1
    3 4 1
    1 1 0 1
    
    Expected output
    -1
    
  3. Example 3

    Input
    4 4
    1 2 1
    2 4 1
    1 3 1
    3 4 1
    1 1 1 1
    
    Expected output
    -1