This page is still under construction.

Parts of this page are still being built. What you see may change.

Beware the Geoducks

Time limit1sMemory limit128 MB

Summary
Given two fixed walking routes on a weighted graph, decide whether the two travelers ever occupy the same point within t seconds, accounting for nodes with geoducks that make a traveler vanish.
Level

Hard8 of 10

Topics
Implementation, Simulation, Geometry, Math
Solved
No attempts yet

Problem

Stan Velikiy is once again chasing his arch-nemesis, Mario the Wabbit, this time around a circuit. As the amused observer, you have been asked to predict the outcome.

The circuit is a set of nodes connected by wires of given lengths. Stan and Mario each start at one node and follow a predetermined route: a list of nodes visited in order, moving along the wires at a speed of one meter per second. Consecutive nodes in a route are always joined directly by a wire. When a traveler's route runs out, they stay at that final node forever.

If Stan and Mario are ever at the exact same location at the same instant — the same node, or the same point along a wire — Stan apprehends Mario. If more than tt seconds pass without a capture, Stan gives up.

Unknown to both, geoducks sit at some of the nodes. Anyone who reaches a node holding a geoduck vanishes instantly, and once either Stan or Mario vanishes, Stan can never catch Mario. In particular, if the two meet exactly on a node that holds a geoduck, they both vanish and it does not count as a capture.

Input

The first line contains six integers: VV (0≤V≤1000 \le V \le 100), the number of nodes; EE (0≤E≤10000 \le E \le 1000), the number of wires; SS and MM (1≤S,M≤10001 \le S, M \le 1000), the number of nodes in Stan's and Mario's routes, respectively; GG (0≤G≤1000 \le G \le 100), the number of geoducks; and tt (0≤t≤10000 \le t \le 1000), the time limit in seconds.

Each of the next EE lines contains three integers: the two nodes that a wire connects and its length ll (1≤l≤20001 \le l \le 2000). No wire connects a node to itself, and there is at most one wire between any two nodes.

The next SS lines each contain one integer, giving the nodes of Stan's route in the order they are visited.

The next MM lines each contain one integer, giving the nodes of Mario's route in the order they are visited.

The final GG lines each contain one integer, giving a node that holds a geoduck.

Output

Print YES if Stan catches Mario no later than tt seconds after the start, and NO otherwise.

Note

As an illustration, suppose Stan walks from node 1 toward node 2 while Mario walks from node 2 toward node 1 along the same wire, with a geoduck resting on an unrelated node 3 that neither traveler ever reaches. The two meet in the middle of that wire; even if they arrive there exactly when the time limit is reached, Stan still catches Mario.

Examples3

  1. Example 1

    Input
    3 1 2 2 1 3
    1 2 6
    1
    2
    2
    1
    3
    
    Expected output
    YES
    
  2. Example 2

    Input
    2 1 1 1 0 0
    1 2 5
    1
    1
    
    Expected output
    YES
    
  3. Example 3

    Input
    2 1 2 2 0 3
    1 2 5
    1
    2
    2
    1
    
    Expected output
    YES