Given a weighted graph with some marked stations, answer queries asking whether a tanker of capacity b can travel from station x to station y, refuelling only at stations.
Hard8GraphShortest pathUnion-findSortingNo attempts yetTime limit2sMemory limit512 MBByteasar works in the logistics department of Byteoil, the petroleum company of Byteotia. His job is to plan fuel deliveries to petrol stations.
Byteotia has n intersections, numbered from 1 to n, and m two-way roads, each connecting a pair of intersections. Some intersections have a Byteoil petrol station.
The Byteoil transport fleet consists of tankers with fuel tanks of various capacities. A tanker burns 1 litre of petrol per kilometre travelled, so a tanker whose tank holds b litres can cover at most b kilometres without refuelling. Drivers cannot use the fuel carried as cargo, but they can fill the tank free of charge at any Byteoil petrol station.
Byteasar's work consists of answering the following query over and over: can a tanker with a tank of capacity b litres drive from the petrol station at intersection x to the petrol station at intersection y? A tanker with a tank of capacity b litres cannot drive more than b kilometres without passing a Byteoil petrol station. Every trip starts at an intersection with a Byteoil petrol station and ends at an intersection with a Byteoil petrol station.
Help Byteasar answer his logistic queries automatically.
The first line contains three integers n, s and m (2≤s≤n≤200000, 1≤m≤200000): the number of intersections, the number of petrol stations and the number of roads in Byteotia. The second line contains s pairwise distinct integers c1,c2,…,cs (1≤ci≤n), the intersections with a Byteoil station.
The next m lines describe the roads. The i-th of these lines contains three integers ui, vi and di (1≤ui,vi≤n, ui=vi, 1≤di≤10000): the i-th road is di kilometres long and connects intersection ui with intersection vi. Each pair of intersections is connected by at most one road.
The next line contains one integer q (1≤q≤200000), the number of queries. Each of the following q lines describes one query. The i-th of these lines contains three integers xi, yi and bi (1≤xi,yi≤n, xi=yi, 1≤bi≤2×109), asking whether a tanker with a tank of capacity bi litres can drive from the petrol station at intersection xi to the petrol station at intersection yi. Both intersections xi and yi have a Byteoil petrol station.
Print exactly q lines. The i-th line contains the single word TAK (yes) if a tanker with a tank of capacity bi litres can drive from intersection xi to intersection yi, and NIE (no) otherwise.