CF652E.Pursuit For Artifacts

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience.

In that country there are nn islands and mm bridges between them, so you can travel from any island to any other. In the middle of some bridges are lying ancient powerful artifacts. Johnny is not interested in artifacts, but he can get some money by selling some artifact.

At the start Johnny is in the island aa and the artifact-dealer is in the island bb (possibly they are on the same island). Johnny wants to find some artifact, come to the dealer and sell it. The only difficulty is that bridges are too old and destroying right after passing over them. Johnnie's character can't swim, fly and teleport, so the problem became too difficult.

Note that Johnny can't pass the half of the bridge, collect the artifact and return to the same island.

Determine if Johnny can find some artifact and sell it.

输入格式

The first line contains two integers nn and mm ( 1<=n<=31051<=n<=3·10^{5} , 0<=m<=31050<=m<=3·10^{5} ) — the number of islands and bridges in the game.

Each of the next mm lines contains the description of the bridge — three integers xix_{i} , yiy_{i} , ziz_{i} ( 1<=xi,yi<=n1<=x_{i},y_{i}<=n , xiyix_{i}≠y_{i} , 0<=zi<=10<=z_{i}<=1 ), where xix_{i} and yiy_{i} are the islands connected by the ii -th bridge, ziz_{i} equals to one if that bridge contains an artifact and to zero otherwise. There are no more than one bridge between any pair of islands. It is guaranteed that it's possible to travel between any pair of islands.

The last line contains two integers aa and bb ( 1<=a,b<=n1<=a,b<=n ) — the islands where are Johnny and the artifact-dealer respectively.

输出格式

If Johnny can find some artifact and sell it print the only word "YES" (without quotes). Otherwise print the word "NO" (without quotes).

输入输出样例

  • 输入#1

    6 7
    1 2 0
    2 3 0
    3 1 0
    3 4 1
    4 5 0
    5 6 0
    6 4 0
    1 6
    

    输出#1

    YES
    
  • 输入#2

    5 4
    1 2 0
    2 3 0
    3 4 0
    2 5 1
    1 4
    

    输出#2

    NO
    
  • 输入#3

    5 6
    1 2 0
    2 3 0
    3 1 0
    3 4 0
    4 5 1
    5 3 0
    1 2
    

    输出#3

    YES
    
首页