This page is still under construction.

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

Vacation Planning

Time limit3sMemory limit256 MB

Summary
Given a flight network where every edge touches one of K hubs, count how many of Q trip requests are reachable and sum their cheapest costs.
Level

Medium6 of 10

Topics
Shortest path, Graph
Solved
No attempts yet

Problem

Air Bovinia runs flights between the NN farms where the cows live (1≤N≤200001 \le N \le 20000). KK of those farms are hubs (1≤K≤2001 \le K \le 200, K≤NK \le N).

The airline currently offers MM one way flights (1≤M≤200001 \le M \le 20000). Flight ii goes from farm uiu_i to farm viv_i and costs did_i dollars (1≤di≤100001 \le d_i \le 10000). On every flight at least one of uiu_i and viv_i is a hub. Two farms have at most one direct flight in a given direction, and no flight starts and ends at the same farm.

Bessie runs the ticket desk for Air Bovinia. While she was away chewing delicious hay for a few hours, QQ one way travel requests for the holiday vacations arrived (1≤Q≤500001 \le Q \le 50000). Request ii asks for a ticket from farm aia_i to farm bib_i.

Decide for each request whether it can be fulfilled, and find its minimum cost when it can.

To keep the output small, print only how many requests can be fulfilled and the minimum total cost of fulfilling those requests. That total may not fit in a 32 bit integer.

Input

  • Line 1: the integers NN, MM, KK, and QQ.
  • Lines 2 to M+1M + 1: uiu_i, viv_i, and did_i. (1≤ui,vi≤N1 \le u_i, v_i \le N, ui≠viu_i \ne v_i)
  • Lines M+2M + 2 to M+K+1M + K + 1: each line holds the ID of one hub, between 11 and NN.
  • Lines M+K+2M + K + 2 to M+K+Q+1M + K + Q + 1: two numbers per line, a ticket request from farm aia_i to farm bib_i. (1≤ai,bi≤N1 \le a_i, b_i \le N, ai≠bia_i \ne b_i)

Output

  • Line 1: the number of ticket requests that can be fulfilled.
  • Line 2: the minimum total cost of fulfilling those requests.

Hint

In the example the first request can only travel farm 1 → 2 → 3 at a cost of 20. No flight leaves farm 3, so the second request cannot be fulfilled.

Examples1

  1. Example 1

    Input
    3 3 1 2
    1 2 10
    2 3 10
    2 1 5
    2
    1 3
    3 1
    
    Expected output
    1
    20