In the event of technical difficulties with Szkopuł, please contact us via email at szkopul@fri.edu.pl.
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Byteasar is employed in the logistics department of Byteonian petroleum giant Byteoil. His job is to plan fuel deliveries to petrol stations.
There are intersections in Byteotia (marked by numbers
from
to
) and
two-way roads connecting
certain pairs of intersections.
There are Byteoil petrol stations located at some intersections.
Byteoil transport fleet consists of petrol tankers with various capacities of fuel tanks.
Each tanker consumes 1 litre of petrol
per kilometre of distance travelled.
It can therefore be assumed that a tanker having tank capacity of
litres can cover a maximum distance of
kilometres
without the need to refuel.
Drivers cannot use the fuel carried by the tanker in the main tank,
however they can refuel at any Byteoil petrol stations free of charge.
Byteasar's work consists of repeatedly answering the following queries:
Is a petrol tanker with a fuel tank of capacity of litres capable of covering the
distance of from a petrol station located at the intersection
to a petrol station located at the intersection
?
Tanker with a fuel tank of capacity of
litres cannot cover a distance of more than
kilometres, during which
there will be no Byteoil petrol station.
Tankers starting point is always located at an intersection where Byteoil petrol
station is present, and also all the trips end at an intersection with Byteoil petrol station.
Help Byteasar to provide an automated reply to his logistic queries.
The first line of input contains three integers
,
and
(
,
),
denoting the number of intersections,
the number of petrol stations and the number of roads in Byteotia.
The second line contains a sequence of
pairwise distinct integers
(
),
denoting the intersections where Byteoil stations are located.
The next lines describe the roads in Byteotia;
-th of these lines contains three integers
,
and
(
,
,
),
indicating that the
-th road has a length of
kilometres
and connects the intersection
with the intersection
.
Each pair of intersections is connected by at most one road.
The next line contains one integer (
),
denoting the number of queries.
The consecutive
lines hold the descriptions of queries;
-th of these lines contains three integers
,
and
(
,
,
)
indicating query concerning the possibility of a tanker with a capacity of
litres to cover the distance from a petrol station at the intersection
to the station
at the intersection of
.
It can be assumed that at both intersections
,
Byteoil petrol stations are located.
Your program should output exactly lines.
The
-th of these lines should contain one word
TAK (i.e., yes) or NIE (i.e., no), depending on whether the tanker with a fuel tank
with a capacity of
is able to travel from the intersection
to the intersection
.
For the input data:
6 4 5 1 5 2 6 1 3 1 2 3 2 3 4 3 4 5 5 6 4 5 4 1 2 4 2 6 9 1 5 9 6 5 8
the correct result is:
TAK TAK TAK NIE
Task author: Jakub Lacki.
<Submit a solution> [0/1]