#Q87. 「一本通 3.3 练习 2」虫洞 Wormholes
「一本通 3.3 练习 2」虫洞 Wormholes
Description
Original source: USACO 2006 Dec. Gold, original problem can be found at POJ 3259
While wandering around his farm, John discovered several wormholes. A wormhole can be considered a very peculiar directed edge that can transport you back to a moment in the past (relative to the time before you entered the wormhole). Each of John's farms consists of fields (labeled from to ) connected by bidirectional paths (undirected edges) and wormholes.
Now John wants to use these wormholes to go back in time (return to the starting point before the departure time). Please tell him if this is possible. John will provide you with the maps of farms. No path will take you more than seconds to traverse, and no wormhole will take you back more than seconds.
Input Format
The first line contains an integer , the number of farms;
For each farm:
The first line contains three integers ;
The next lines each contain three integers , indicating a bidirectional path between field and field that takes seconds to traverse;
The next lines each contain three integers , indicating a wormhole from field to field that transports John seconds into the past.
Output Format
Output lines in total. For the -th farm, if John can achieve his goal, output YES on the -th line; otherwise, output NO.
Sample 1
2
3 3 1
1 2 2
1 3 4
2 3 1
3 1 3
3 2 1
1 2 3
2 3 4
3 1 8
NO
YES
Data Range and Hints
For all data, , , , , , .