Moving between FloorsProblem code: FLOORSMV |
All submissions for this problem are available.
Did you know that the world's tallest structure is Burj Khalifa in Dubai ? To survive when the world ends, Mr.Turing thinks that he should climb one of those skyscrapers ( tall buildings ). There are N tall buildings numbered b_1, b_2, ... , b_N in that order and b_i and b_i+1 are adjacent to each other for 1 ? i < N. Each of these have exactly F number of floors, f_1, f_2, ... , f_F from bottom to top. Floors f_i and f_i+1 in the same building are adjacent to each other for 1 ? i < F and it takes one unit of time to move between them. It also takes one unit of time to move between the floor f_1 of a building and f_1 of its adjacent building.
Turing is afraid that some buildings may still collapse and so he lists down the bridges connecting some of them, to know how to escape quickly. There are M bridges, each of which connects two floors of different buildings. Each of these bridges is given as bi fi T bj fj, meaning it takes T units of time to move along this bridge which connects the floor fi of building bi and the floor fj of building bj. All ways are bidirectional. Turing wants to know, given bq and fq, the sum of the shortest time it takes to reach (b,f) starting from (bq,fq), for all possible 1 ? b ? N ( except b = bq ) and 1 ? f ? F. In other words, given (bq,fq), find the value of D(bq,fq,b,f) for all possible (b,f) except b = bq, where D(bi,fi,bj,fj) is the shortest time it takes to reach floor fi of building bi from floor fj of building bj. Get ready to answer his Q such queries.
Input
First line contains N F M. N is the number of buildings , F is the number of floors in each building and M is the number of bridges. M lines follow, each of the form bi fi T bj fj, as mentioned in the problem statement. Next line contains Q, the number of queries and Q lines follow, each of the form bq bf
Output
For each test case, output the sum of the shortest time it takes from (bq,fq) to reach each floor of every other building.
Constraints
2 ? N, M ? 1001 ? F, T ? 1,000,000
1 ? Q ? 2012
1 ? bi,bj,bq ? N and 1 ? fi,fj,fq ? F
Example
Input: 2 4 1 1 3 1 2 3 3 1 1 1 2 1 3 Output: 10 10 8
Note : There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted.
| Author: | flying_ant |
| Date Added: | 9-01-2012 |
| Time Limit: | 3 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions
