File size: 2,841 Bytes
f7ba5f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
**Note: This problem has large input, so we recommend pre-downloading the compressed zip file.**
Meta Getaways is a travel agency that deals with \(N\) airports numbered \(1...N\), and \(M\) flight paths. Flight path \(i\) connects airports \(A_i\) and \(B_i\) in both directions, with two direct flights operating every morning (one in each direction), and another two every evening (also one in each direction). Each of these four direct flights can carry up to \(C_i\) **t**ourists.
{{PHOTO_ID:356437426702208|WIDTH:400}}
The first sample case is depicted above, with morning and evening flights in red and blue.
Peak travel season is here, and will last \(Q\) days. For each day \(i\), determine \(F_i\), the maximum number of tourists who could possibly fly from airport \(X_i\) to \(Y_i\). Each tourist may either fly directly or take one morning and one evening flight which share an intermediate airport.
# Constraints
\(1 \leq T \leq 70 \)
\(1 \leq N, M, Q \leq 200{,}000\)
\(1 \leq C_i \leq 10^9 \)
\(1 \leq A_i, B_i \leq N; A_i \ne B_i \)
\(1 \leq X_i, Y_i \leq N; X_i \ne Y_i\)
All unordered pairs \((A_i, B_i)\) within a given test case are distinct.
The sum of \(Q\) across all test cases is at most \(5{,}000{,}000\).
# Input Format
Input begins with a single integer \(T\), the number of test cases. For each case, there is first a line containing three space-separated integers \(N\), \(M\), and \(Q\). Then, \(M\) lines follow, the \(i\)th of which contains three space-separated integers \(A_i\), \(B_i\), and \(C_i\). Then, \(Q\) lines follow, the \(i\)th of which contains two space-separated integers \(X_i\) and \(Y_i\).
# Output Format
For the \(i\)th case, print a line containing "`Case #i:` " followed by \(Q\) space-separated integers \(F_1, ..., F_Q\).
# Sample Explanation
In the first case:
- On day \(1\), we must send as many tourists from airport \(1\) to airport \(2\). We can fly \(10\) tourists direct in the morning and \(10\) more at night. Only \(5\) tourists can be flown from \(1 \to 3\) in the morning and \(3 \to 2\) in the evening (despite the evening flight capacity being \(15\)). Therefore, \(F_1 = 10 \cdot 2 + 5 = 25\).
- On day \(2\), we can fly \(5\) tourists direct in the morning and evening, then fly \(10\) tourists through airports \(1 \to 2 \to 3\). Therefore, \(F_2 = 5 \cdot 2 + 10 = 20\).
- \(F_3 = 15 \cdot 2 + 5 + 7 = 42\)
- \(F_4 = 10 \cdot 2 + 7 = 27\)
- \(F_5 = 7 \cdot 2 + 10 = 24\)
- On day \(6\), there are no direct flights. We can fly \(10\) tourists through airports \(4 \to 2 \to 1\), and \(5\) tourists through airports \(4 \to 3 \to 1\) for a total of \(F_6 = 10 + 5 = 15\) tourists.
In the second case:
- \(F_1 = 10 \cdot 2 + 20 = 40\)
- \(F_2 = 30 \cdot 2 + 10 = 70\)
- \(F_3 = 0\)
- \(F_4 = 20 \cdot 2 + 10 = 50\)
- \(F_5 = 0\)
- \(F_6 = 0\)
|