Under construction

Still being built. Things may change

Escape Plan

Interview

Time limit2sMemory limit1024 MB

Summary
For each room, find the nearest exit left open after the K nearest exits close, breaking distance ties by the smaller room number.
Level

Medium6 of 10

Topics
BFS, Graph, Sorting
Solved
No attempts yet

Statement

The blueprints for an innovative power plant were stolen from the office of your energy corporation. If the plant were built, it would solve most problems of modern energy and make you incredibly rich. Do not despair yet. The security service tracked the thief and found that the blueprints are now kept in an underground bunker owned by a competitor. Your best agent has already set out to steal the blueprints back, but the mission is very hard!

The competitor's system still has the Heartbleed vulnerability, so your IT department got limited access to the bunker's security system and found its floor plan. The bunker has NN rooms and MM corridors connecting them. Every corridor can be walked in both directions. No corridor connects a room to itself, and no two rooms are connected by more than one corridor (who would build corridors any other way?).

Some rooms contain exits from the bunker. As soon as an agent takes the blueprints, the alarm goes off in the room where the agent is. After that, all exits close and the agent is trapped.

Our IT team, toughened by CTF competitions, changed the security system so that when the alarm goes off in room ii, not all exits close, only the KK closest to that room. The distance between two rooms is the minimum number of corridors that must be traversed to get from one to the other. Exits at the same distance from room ii close in increasing order of their room numbers.

Input

The first line contains two space-separated integers NN and MM, the number of rooms and corridors (1≤N≤1000001 \le N \le 100000, 0≤M≤1000000 \le M \le 100000). Each of the next MM lines contains two integers aia_i and bib_i, the rooms connected by the ii-th corridor (1≤ai,bi≤N1 \le a_i, b_i \le N). The next line contains AA, the number of rooms with exits (1≤A≤N1 \le A \le N). The next line contains AA distinct space-separated integers eie_i, the rooms with exits (1≤ei≤N1 \le e_i \le N). The last line contains KK, the number of exits closed by the alarm (0≤K≤100 \le K \le 10).

Output

Print NN integers. The ii-th integer is the number of the nearest room with an open exit after the alarm goes off in room ii. If several suitable rooms are equally close, choose the one with the smallest number. If room ii offers no escape, print -1.

Hints

In the first example K=0K = 0, so each room just needs its nearest exit. The answer is unique for every room except room 2. Rooms 1 and 3 each have an exit one corridor away, so the answer is the smaller number, room 1.

In the second example, rooms 6 through 9 cannot escape. Only two exits are reachable from them, and the alarm closes both.

Examples2

  1. Example 1

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

    Input
    9 10
    1 2
    2 3
    3 4
    4 5
    6 7
    6 8
    6 9
    7 8
    7 9
    8 9
    7
    1 2 3 4 5 6 7
    2
    
    Expected output
    3 3 4 5 3 -1 -1 -1 -1