编程介的小学生 2017-02-15 15:23 采纳率: 20.5%
浏览 803
已采纳

Help John!

John is 7 years old and he lives in Faegfalch, which is a very dangerous city, so John must go to school according to the path his mother told him. This way isn't the fastest way from John's home to school. John is a very lazy boy and he doesn't like walking, so he is searching for the fastest way from home to school. He only has to make sure, that his mother can not see from her flat window that he is going on another way (he must pass the first crossroad where mother told him to go across, and never walk back home unless he comes back from school).

INPUT

First line of input includes t (1<=t<=77) - the number of test cases.

First line of every test includes n (1<=n<=1 000) - the number of crossroads in Faegfalch and m (1<=m<=30 000) - the number of roads. In next m lines there are descriptions of roads. Every road description includes three numbers: a, b (1<=a, b<=n) - crossroads, where the road starts and ends and c (1<=c<=1 000) - the time needed to walk by this street (John can't walk faster, because if he did it, he would be cought by Faegnad (football team) fans and he can't go slower, because he doesn't want to be late and he wants to talk with his friends and make some homework before lessons start). In next line there is an integer k (1<=k<=m) - the number of crossroads, which his mother told him to meet. Next line includes k crossroads which he has to meet.

The boy's home is always at location 1 and the school positions at location n. All the paths are bidirectional.

OUTPUT

Output has one line for every test, which include word "TEST" and then the order number. Print the character "Y" if John can go to his school from home, and the time needs to go to school by roads which his mother told him to go, subtracts the minimal time which he needs to walk to school that can not be seen by his mother. Output only an "N" if there is no way to his school.

SAMPLE

INPUT

2
6 10
1 2 2
1 3 2
1 6 1
2 6 4
2 3 3
2 4 1
3 4 5
4 5 1
4 6 3
5 6 2
6
1 2 3 4 5 6
3 1
1 2 1
3
1 2 3

(Explanation for the first sample. the way his mother told him is 1->2->3->4->5->6, with a total length of 13. And the shortest path he can find is 1->2->6, with a total length of 6. So the final output is 13 - 6 = 7.)

OUTPUT

TEST 1 Y 7
TEST 2 N

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-02-20 17:17
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)