#BF0000012. Giao thông thành phố (Traffic)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giao thông thành phố (Traffic)
Traffic
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A directed road u to v costs the cube of the difference in busyness. Return ? for unreliable distance queries.
Each city has a busyness value . A directed road from to has cost , the cube of the difference in busyness. This value may be negative even though busyness values are nonnegative. Trips start in city .
For each query destination , find the shortest path cost from city . The answer is unreliable if is unreachable, if its shortest distance is less than , or if a negative cycle reachable from the source can affect . Print ? for all such cases and the integer distance otherwise.
Input
Read and busyness values, then directed road pairs , then and query vertices.
Output
Print Set #1, then an integer or ? for each query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
5
6 7 8 9 10
6
1 2
2 3
3 4
1 5
5 4
4 5
2
4
5
Output
Set #1
3
4
Explanation
Relaxation finds eligible paths, or a negative cycle in the required scope. The sample uses the exact output tokens specified by the problem.