This page is still under construction.

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

Meeting in the Middle

Interview

Time limit1sMemory limit512 MB

Summary
Given a directed weighted graph and a set of K home cities, pick every city X such that the maximum over all homes of the round-trip distance to X and back is minimized, printing the chosen city numbers in ascending order.
Level

Medium6 of 10

Topics
Graph, Shortest path, Brute force, Implementation
Solved
No attempts yet

Problem

Junhyung has arranged to meet his friends tomorrow. Junhyung and his friends live in different cities.

The roads connecting the cities are one-way only, so the time to travel from city AiA_i to city BiB_i may differ from the time to travel from city BiB_i to city AiA_i.

Junhyung and his friends want to choose a city XX that satisfies the conditions below and meet there.

  • The round-trip time is the sum of the time to travel from one's home city to city XX and the time to travel from city XX back to one's home city.
  • They only choose a city that Junhyung and his friends can reach using the roads.
  • They choose the city XX that minimizes the maximum of the round-trip times of Junhyung and his friends.
  • It is guaranteed that there is at least one city that Junhyung and his friends can travel to.

There are many cities, so this is hard to compute. Let us tell Junhyung and his friends the city XX on their behalf.

Input

The first line gives the number of cities NN and the number of roads MM.

From the second line to line M+1M + 1, the city AiA_i, the city BiB_i, and the time TiT_i it takes to travel from city AiA_i to city BiB_i are given, separated by spaces.

Line M+2M + 2 gives the total number of people, Junhyung and his friends, KK.

Line M+3M + 3 gives the numbers CiC_i of the cities where Junhyung and his friends live, separated by spaces.

Output

Print the number of the city XX that satisfies the conditions above. If there are multiple possible cities XX, print the city numbers in ascending order.

Constraints

  • 3≤N≤2003 \le N \le 200
  • 2≤K≤N2 \le K \le N
  • 1≤M≤N×(N−1)1 \le M \le N \times (N - 1)
  • 1≤Ci≤N1 \le C_i \le N
  • 1≤T≤1,0001 \le T \le 1,000

Examples2

  1. Example 1

    Input
    4 9
    1 2 9
    2 3 9
    3 1 9
    1 4 1
    4 1 1
    2 4 1
    4 2 1
    3 4 1
    4 3 1
    3
    1 2 3
    
    Expected output
    4
    
  2. Example 2

    Input
    3 3
    1 2 1
    2 3 1
    3 1 1
    2
    1 2
    
    Expected output
    1 2 3