Note that this is not an approximate task. It is labeled as an approximate task because of multiple solutions.
Given a graph with N vertices and M edges. There are D type of edges. the ith (1≤i≤D) type of edges you can use at second i. You have K pointers, in the second 0 they are situated in s1,s2,…,sK. Each second you instantly move all the points through some of the allowed edges with the condition that you can't move two pointers in the same vertex. At the (D+1) you stop moving them.
Provide a way to move the pointers at each second. It is guaranteed that there's always a solution.
Input
The first line contains four integers - N,M,K,D(1≤D≤100,1≤K≤N≤500,1≤M≤50000).
The next line contains K integers - s1,s2,…,sK (1≤s1<s2<⋯<sK≤N).
The next M lines contain three integers - x,y,z(1≤x,y≤N,1≤z≤D), meaning there is a directed edge (x,y) of type z
Output
Output K lines, each containing D+1 integers. The jth number on the ith line represents the vertex where will be the ith pointer at the second j−1.
N/A