#BF0000008. Lỗ sâu và đường bộ (Wormholes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lỗ sâu và đường bộ (Wormholes)
Wormholes
Source: BOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Detect a negative cycle anywhere in a graph of positive two-way roads and negative one-way wormholes.
There are locations, ordinary roads and wormholes. An ordinary road connects two locations in both directions and takes time units either way. A wormhole is a one-way edge with travel time .
Determine whether some closed itinerary lets the traveler return to the departure point before leaving. No fixed source is specified, so a negative cycle in any component makes the answer YES. Treat each road description as two directed edges, but each wormhole as only one.
Input
First line . Then two-way roads and one-way wormholes with actual time .
Output
Print YES when any negative cycle exists, else NO.
Subtasks
- Subtask 1 (20 points): ; ; ; ; two-way roads, one-way wormholes.
- Subtask 2 (30 points): ; ; ; ; two-way roads, one-way wormholes.
- Subtask 3 (50 points): ; ; ; ; two-way roads, one-way wormholes.
Examples
Input
3 1 1
1 2 3
2 1 7
Output
YES
Explanation
Relaxation finds eligible paths, or a negative cycle in the required scope. The sample uses the exact output tokens specified by the problem.