Codeforces 652E Pursuit For Artifacts 【边双连通 缩点】

Johnny在一款电脑游戏中试图找到并出售古文物,游戏中的岛屿由桥梁连接,部分桥梁含有文物。Johnny需要从初始岛屿到达商人岛屿并出售文物,但走过桥梁后桥梁会消失。问题在于判断Johnny是否能成功找到并出售文物。解决方案包括边双连通分量的分析,寻找包含正权边的分量,并通过缩点后的最远路径搜索策略。
摘要由CSDN通过智能技术生成

题目链接:Codeforces 652E Pursuit For Artifacts

E. Pursuit For Artifacts
time limit per test3 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
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.

Input
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 xi, yi, zi (1 ≤ xi, yi ≤ n, xi ≠ yi, 0 ≤ zi ≤ 1), where xi and yi are the islands connected by the i-th bridge, zi 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.

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

Examples
input
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
output
YES
input
5 4
1 2 0
2 3 0
3 4 0
2 5 1
1 4
output
NO
input
5 6
1 2 0
2 3 0
3 1 0
3 4 0
4 5 1
5 3 0
1 2
output
YES

题意:n个点m条无向边,保证图联通,每条边只能走一次

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值