Under construction

Still being built. Things may change

Choosing a Room

Interview

Time limit2sMemory limit1024 MB

Summary
Given a graph with random edge weights, find all rooms from which some walk to school (vertex 1) has expected total time at most T.
Level

Medium6 of 10

Topics
Shortest path, Graph
Solved
No attempts yet

Problem

Hyeonseo, a freshman, has a lot on their mind again this semester. The biggest worry is that many morning classes make it hard to reach the lecture hall on time. After some thought, Hyeonseo decided to rent a room near school.

The area around the school is a graph with NN vertices and MM edges. The school is at vertex 1, and every other vertex has one room that Hyeonseo could rent. An edge is a road between the school and a room, or between two rooms. Roads can be used in both directions.

Each road has a traffic value. Crossing a road with traffic xx takes xx minutes in either direction. Traffic is not fixed because of various events. Specifically, the traffic on road ii is aia_i with probability 1/2 and bib_i with probability 1/2. Each road's traffic is chosen independently, and it can change every time Hyeonseo walks along the road. aia_i or bib_i may be negative, in which case time runs backward when crossing that road.

For every vertex ii other than vertex 1, let WiW_i be the set of all possible walks from vertex ii to vertex 1.

  • A walk from ss to ee starts at ss, follows connected roads only, and ends at ee.
  • A walk may reuse the same road any number of times. Reaching vertex 1 does not require stopping there.

For each 2≤i≤N2 \le i \le N, define fi:Wi→Rf_i : W_i \to \mathbb{R} by

fi(w)f_i(w) = (the expected time in minutes to reach vertex 1 from vertex ii by following walk ww)

Here R\mathbb{R} is the set of all real numbers.

Hyeonseo only considers vertices ii for which some w∈Wiw \in W_i satisfies fi(w)≤Tf_i(w) \le T. Find all rooms that satisfy this condition.

Input

The first line contains the number of vertices NN and the number of edges MM (1≤N,M≤2000001 \le N, M \le 200000).

Each of the next MM lines contains two vertices uiu_i and viv_i joined by edge ii, followed by integers aia_i and bib_i, separated by spaces. (1≤ui,vi≤N1 \le u_i, v_i \le N; ui≠viu_i \ne v_i; −109≤ai,bi≤109-10^9 \le a_i, b_i \le 10^9) No pair of vertices is joined twice. That is, for all 1≤i,j≤M1 \le i, j \le M, if {ui,vi}={uj,vj}\{u_i, v_i\} = \{u_j, v_j\} then i=ji = j.

Line M+2M+2 contains the integer TT (−2×1015≤T≤2×1015-2 \times 10^{15} \le T \le 2 \times 10^{15}).

Output

The first line contains the number KK of rooms that satisfy the condition. If no room satisfies it, print 0.

If the first line is not 0, the second line lists the vertex numbers of the rooms that satisfy the condition in ascending order, separated by spaces.

Hint

In the first example, for vertex 2, the walk 2 → 3 → 1 gives an expected time of 4 minutes. For vertex 3, the walk 3 → 1 gives an expected time of 2.5 minutes. As the third example shows, some rooms may be unreachable from the school.

Examples4

  1. Example 1

    Input
    4 5
    1 2 7 5
    1 3 1 4
    2 3 1 2
    2 4 6 2
    3 4 2 3
    4
    
    Expected output
    2
    2 3
    
  2. Example 2

    Input
    4 4
    1 2 2 4
    2 3 3 5
    1 3 -3 1
    3 4 5 7
    -3
    
    Expected output
    3
    2 3 4
    
  3. Example 3

    Input
    6 5
    1 2 8 -4
    1 3 2 3
    2 3 0 4
    3 4 -1 1
    5 6 -1 -1
    2
    
    Expected output
    1
    2
    
  4. Example 4

    Input
    3 3
    1 2 9 10
    1 3 -3 27
    2 3 -11 11
    5
    
    Expected output
    0