#BF0000007. Lỗ sâu thời gian (Wormholes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lỗ sâu thời gian (Wormholes)
Wormholes
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Determine whether a reachable directed negative cycle permits travel into the past.
A wormhole network is a directed graph with vertices numbered through . Traveling along an edge changes the time by an integer . A negative value means traveling backward through time. Every vertex is reachable from vertex .
Determine whether a traveler can follow a closed path and return to the starting place earlier than the departure time. This is possible exactly when the graph has a negative-weight cycle. Report only whether such a cycle exists; do not output its vertices.
Input
First line: . Next lines , vertices from 0 to .
Output
Print possible for a negative cycle, otherwise not possible.
Subtasks
- Subtask 1 (20 points): ; ; ; all vertices reachable from 0; no self-loops or parallel directed edges.
- Subtask 2 (30 points): ; ; ; all vertices reachable from 0; no self-loops or parallel directed edges.
- Subtask 3 (50 points): ; ; ; all vertices reachable from 0; no self-loops or parallel directed edges.
Examples
Input
3 3
0 1 1
1 2 -5
2 1 1
Output
possible
Explanation
Relaxation finds eligible paths, or a negative cycle in the required scope. The sample uses the exact output tokens specified by the problem.