Under construction

Still being built. Things may change

Cheeseburger

Interview

Time limit1sMemory limit1024 MB

Summary
Each farm supplies only the chain stores nearest to it, and each store pays the cheapest price among farms that can supply it. Output that price per store, or -1.
Level

Medium6 of 10

Topics
Shortest path, Graph
Solved
No attempts yet

Problem

Jeonghu rides the subway often. The subway map has NN stations connected by MM rail lines. The ii-th rail line connects stations uiu_i and viv_i in both directions, and travel between those two stations takes wiw_i time.

One day, Jeonghu ate a cheeseburger at a subway station and came to love cheeseburgers so much that he opened cheeseburger chain stores at stations a1,a2,⋯ ,aKa_1, a_2, \cdots, a_K. All that remains is to transport the cheese.

Jeonghu found TT cheese farms near stations b1,b2,⋯ ,bTb_1, b_2, \cdots, b_T. The cheese at the farm near station bib_i costs cic_i. Jeonghu delivers cheese to each chain store by KTX express, and a KTX express delivery takes the same time as travel between stations.

Each farm can supply cheese to every chain store that has the shortest delivery time from that farm, where the shortest delivery time is taken over one or more chain stores. Each chain store buys the cheapest cheese it can be supplied with. What price does each chain store pay?

Input

The first line contains four integers NN, MM, KK, and TT, separated by spaces.

The second line contains KK integers a1,a2,⋯ ,aKa_1, a_2, \cdots, a_K, separated by spaces.

The next TT lines each contain two integers bib_i and cic_i, separated by a space.

The next MM lines each contain three integers uiu_i, viv_i, and wiw_i, separated by spaces.

Output

Print KK integers on one line, separated by spaces, where the ii-th integer is the price of the cheese that the ii-th chain store buys. If a chain store cannot buy any cheese, print -1 for it.

Constraints

  • 1≤N≤300 0001 \leq N \leq 300\,000
  • N−1≤M≤300 000N-1 \leq M \leq 300\,000
  • 1≤K,T≤N1 \leq K, T \leq N
  • 1≤ai,bi,ui,vi≤N1 \leq a_i, b_i, u_i, v_i \leq N
  • If i<ji<j, then ai<aja_i<a_j and bi<bjb_i<b_j
  • ui<viu_i<v_i
  • 1≤ci,wi≤1 000 000 0001 \leq c_i, w_i \leq 1\,000\,000\,000

Examples1

  1. Example 1

    Input
    6 7 3 4
    2 5 6
    1 5
    3 6
    4 4
    6 10
    1 2 3
    1 3 1
    2 4 3
    3 4 2
    4 5 4
    1 5 3
    5 6 2
    
    Expected output
    4 5 10