#BF0000011. Nghịch lý Farnsworth (The Farnsworth Parabox)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghịch lý Farnsworth (The Farnsworth Parabox)
The Farnsworth Parabox
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Each box i,j,t moves forward by t from i to j, or backwards by t from j to i. Detect a time paradox reachable from universe 1.
There are parallel universes, with universe being the original universe. A box permits forward travel advancing time by units, and reverse travel moving back in time by units. There is at most one box per unordered universe pair, but boxes may be reused.
The scientist starts in universe and wants to know whether a closed trip can return to that universe earlier than departure. Individual boxes are not enough to decide this: a combination of boxes may form a negative-total-time cycle. If such a cycle is reachable from the original universe, a zero-time round trip to the cycle can be added to obtain a valid paradoxical itinerary.
Input
First line ; then boxes , each unordered pair appearing at most once.
Output
Print Y if the paradox is possible, otherwise N.
Subtasks
- Subtask 1 (20 points): ; ; ; ; no repeated unordered pairs.
- Subtask 2 (30 points): ; ; ; ; no repeated unordered pairs.
- Subtask 3 (50 points): ; ; ; ; no repeated unordered pairs.
Examples
Input
3 3
1 2 3
1 3 2
2 3 4
Output
Y
Explanation
Relaxation finds eligible paths, or a negative cycle in the required scope. The sample uses the exact output tokens specified by the problem.