Trucks
InterviewTime limit1sMemory limit1024 MB
Given roads with travel times, answer each query by checking whether a driver can get from city a to city b when every road on the route fits within the rest limit p.
- Level
Medium6 of 10
- Topics
- Minimum spanning tree, Union-find, Tree
- Solved
- No attempts yet
Statement
A worldwide logistics company is called Loners since all of its drivers ride alone. The managers must quickly and accurately tell their clients whether a driver can deliver goods safely from city to city .
The job demands responsibility and alertness. Drivers must rest at a hotel no less often than every hours. Every city has a hotel. Using the cities and the roads that connect them, write a program that answers the managers' queries.
Input
The first line contains three integers , , and , separated by spaces: the number of cities, the number of roads, and the number of manager queries. The cities are numbered from to .
Each of the next lines contains three integers , , and . This means it takes time to drive from city to city . Roads are two-way, and the time is the same in both directions. The data always satisfies . Two cities have at most one direct road between them.
Each of the next lines contains three integers , , and . Here is the starting city, is the destination city, and is the maximum time the driver can drive without rest. The data always satisfies .
Output
For each query, print TAIP (Lithuanian for "yes") on its own line if the driver can safely deliver the goods from city to city . Otherwise, print NE (Lithuanian for "no").