Under construction

Still being built. Things may change

Rabbit vs Turtle

Time limit1sMemory limit512 MB

Summary
Count the nodes on Stan's path where he can switch to the shortest route to node N and still beat George, who may be sleeping on his own path.
Level

Medium7 of 10

Topics
Shortest path, Prefix sum, Graph
Solved
No attempts yet

Problem

A rabbit named Stan and a turtle named George race on a graph with NN nodes and MM edges. The race starts at node 1 and ends at node NN. Each racer picks a path before the race. Both know the graph, both paths, and the time each racer needs to cross each edge.

George chooses some nodes on his path where he sleeps for a while. If George realizes that Stan is cheating, he stops sleeping and runs straight to the finish.

Stan does not intend to keep his promise. At some node he plans to switch from his assigned path to the shortest path to node NN. He can change paths only while he is at a node, never while he is on an edge. If Stan cheats while George is awake, George notices at once. If George is asleep, he notices when he wakes up.

Count the moments when Stan can switch paths and still win the race.

Input

The first line contains NN and MM. Each of the next MM lines has four values AA, BB, TT, RR, meaning there is an edge from node AA to node BB. George needs TT time units to cross it, and Stan needs RR time units. The ii-th edge has index ii.

The next line contains PTP_T, the number of nodes on George's path. The next PTP_T lines each contain an edge index and a sleep time: the edge George uses next, and how long he sleeps after using it. The sleep value on the last edge does not matter, since George reaches the finish.

The next line contains PRP_R, the number of edges on Stan's initial path. The last line contains PRP_R edge indices, the edges Stan uses in order.

Output

On the first line, print xx, the number of moments when Stan can cheat. On the second line, print the xx node indices in ascending order.

Constraints

  • 2≤N≤1000002 \le N \le 100000
  • 1≤PR,PT<1000001 \le P_R, P_T < 100000
  • 1≤M≤2000001 \le M \le 200000
  • 1≤T,R≤10000000001 \le T, R \le 1000000000
  • 0≤sleep≤10000000000 \le \text{sleep} \le 1000000000
  • The edges in the path descriptions are given in the correct order.
  • The nodes on George's path do not repeat.
  • The nodes on Stan's path do not repeat.
  • If Stan and George reach the finish at the same time, Stan wins.
  • If Stan cheats at the exact moment George starts to sleep, George falls asleep first and notices the cheating only after waking up.
  • Stan cheats only if he leaves his original path and the new path is strictly faster than the rest of the original path.
  • The cheating path may share nodes with the original path. At the moment of cheating, Stan must take a different edge from his original one. He may return to the previous node if an edge allows it.

Examples2

  1. Example 1

    Input
    8 12
    1 2 2 10
    2 3 1 10
    3 8 2 10
    1 4 10 3
    4 5 10 2
    5 6 10 4
    6 8 10 2
    1 7 10 5
    4 7 10 2
    5 7 10 2
    6 7 10 1
    7 8 10 1
    3
    1 3
    2 2
    3 0
    4
    4 5 6 7
    
    Expected output
    2
    4 5
    
  2. Example 2

    Input
    6 6
    1 4 1 3
    4 6 1 1
    4 2 1 6
    2 6 6 6
    3 4 2 3
    1 3 4 5
    2
    1 2
    2 0
    4
    6 5 3 4
    
    Expected output
    0