A10297 | Pursuit For Artifacts
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted