303363: CF652E. Pursuit For Artifacts

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Pursuit For Artifacts

题意翻译

- 给定一张 $n$ 个点 $m$ 条边的简单无向连通图,边有边权,边权要么为 $0$,要么为 $1$。 - 每条边只能通过一次(两个方向加起来只能通过一次)。 - 求是否存在一条从 $a$ 到 $b$ 的路径,满足路径上至少存在一条权为 $1$ 的边。 - $1 \leq n, m \leq 3 \times 10^5$。

题目描述

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.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 1<=n<=3·10^{5} $ , $ 0<=m<=3·10^{5} $ ) — 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.

输出格式


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

Input

题意翻译

- 给定一张 $n$ 个点 $m$ 条边的简单无向连通图,边有边权,边权要么为 $0$,要么为 $1$。 - 每条边只能通过一次(两个方向加起来只能通过一次)。 - 求是否存在一条从 $a$ 到 $b$ 的路径,满足路径上至少存在一条权为 $1$ 的边。 - $1 \leq n, m \leq 3 \times 10^5$。

加入题单

上一题 下一题 算法标签: