CF652E.Pursuit For Artifacts

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

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 n islands and m 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 a and the artifact-dealer is in the island b (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.

约翰尼正在玩一款著名的电脑游戏。游戏中设定在某个国家,玩家可以在其中自由旅行、完成任务并获得经验值。

该国共有 nn 座岛屿和 mm 座连接它们的桥梁,使得任意两座岛屿之间均可互相到达。某些桥梁的中点处放置着古老的强力遗物。约翰尼对这些遗物本身并不感兴趣,但他可以通过出售某些遗物来获取金钱。

初始时,约翰尼位于岛屿 aa,而遗物商人位于岛屿 bb(二者可能位于同一座岛屿)。约翰尼希望找到某件遗物,前往商人处并将它卖掉。唯一的难点在于:这些桥梁过于古老,一旦被经过便会立即损毁。约翰尼的角色既不能游泳、也不能飞行或传送,因此这个问题变得极为困难。

注意:约翰尼不能仅走过某座桥的一半、拾取遗物,再返回原岛屿。

请判断约翰尼是否能够找到某件遗物并成功将其售出。

输入格式

The first line contains two integers n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of islands and bridges in the game.

Each of the next m lines contains the description of the bridge — three integers x__i, y__i, z__i (1 ≤ x__i, y__i ≤ n, x__i ≠ y__i, 0 ≤ z__i ≤ 1), where x__i and y__i are the islands connected by the i-th bridge, z__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 a and b (1 ≤ a, b ≤ n) — the islands where are Johnny and the artifact-dealer respectively.

第一行包含两个整数 nn 和 mm(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5,0≤m≤3⋅1050 \leq m \leq 3 \cdot 10^5)—— 分别表示游戏中的岛屿数量和桥梁数量。

接下来的 mm 行每行描述一座桥梁——包含三个整数 xix_i、yiy_i、ziz_i(1≤xi,yi≤n1 \leq x_i, y_i \leq n,xi≠yix_i \neq y_i,0≤zi≤10 \leq z_i \leq 1),其中 xix_i 和 yiy_i 表示第 ii 座桥梁所连接的两座岛屿,ziz_i 在该桥梁上存在宝物时为 11,否则为 00。任意两座岛屿之间至多只有一座桥梁。保证任意两座岛屿之间均可相互到达。

最后一行包含两个整数 aa 和 bb(1≤a,b≤n1 \leq a, b \leq n)—— 分别表示 Johnny 和宝物商人所在的岛屿。

输出格式

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

如果 Johnny 能找到某个文物并将其出售,则输出唯一的单词 “YES”(不带引号)。否则输出单词 “NO”(不带引号)。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页