CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » August Challenge 2012 » Delivery Boy

Delivery Boy

Problem code: HOMDEL

  • All Submissions

All submissions for this problem are available.

Chef has started Home Delivery scheme in one of his restaurants. As the scheme is new , Chef appoints only one employee to deliver food to various locations. The delivery boy who has been appointed is an absent-minded chap. He always forgets to fill fuel in his delivery scooter. So what he does is that whenever Chef sends him for delivery, he goes to the gas station from the restaurant first. He gets his tank filled and then he heads towards his destination. He will do this every single time irrespective of the destination. The delivery boy tries his best to be on time. And to do this, he will choose those paths(from restaurant to gas station AND gas station to destinaion) which cost him the least amount of time. Your task is to tell the Chef how much time can the delivery boy save if he had enough fuel in his scooter i.e. if he went to the destination directly without stopping for fuel (taking the path which costs him least amount of time).

The city has N streets numbered from 0 to N-1. The restaurant is on street number S, the gas station is on street number G and the food has to be delivered to street D . Note that S, G and D need not be distinct.

Input:

First line of the input contains a single integer N.
Then follows an NxN matrix T which is represented in N lines with N space separated integers on each line.
T[i][j] denotes the time taken to move from the ith street to jth street. Obviously, T[i][i] = 0.
Next line contains a single integer M, the number of scenarios.
The following M lines contain 3 space separated integers S, G and D.

Output:

For each of the M scenarios, output the time taken by the delivery boy to deliver the food and the time he could have saved if he went directly from S to D.
Both these values must be on the same line separated by a single space.

Constraints:


1 ≤ N ≤ 250
1 ≤ M ≤ 10000
0 ≤ T[i][j] ≤ 100000
0 ≤ S,G,D ≤ N-1

Example:

Input:
4
0 2 1 3
1 0 4 5
3 1 0 3
1 1 1 0
4
0 2 1
0 2 2
3 1 2
3 0 1

Output:
2 0
1 0
3 2
3 2


Author: vamsi_kavala
Tester: laycurse
Editorial http://discuss.codechef.com/problems/HOMDEL
Date Added: 1-07-2012
Time Limit: 1 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, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Is output for 3 1 2 correct

suneetk92 @ 1 Aug 2012 03:12 PM
Is output for 3 1 2 correct above?? Its output must be 5 4

Output is correct. Hint: He

amit5148 @ 1 Aug 2012 03:36 PM
Output is correct. Hint: He will choose those paths which cost him the least amount of time.

u are right suneetk92

atanu1991 @ 1 Aug 2012 03:46 PM
u are right suneetk92

is there any wrong with test

rohspeed @ 1 Aug 2012 04:08 PM
is there any wrong with test case 3 1 2????? can anybody explain this????

Maybe the input format should

victorjavadore @ 1 Aug 2012 04:36 PM
Maybe the input format should be more precise for the matrix T, since it's noncommutative. (It seems to cause problems to some.)

@admin:Are the t[i][j]s

pratikjain1993 @ 1 Aug 2012 04:44 PM
@admin:Are the t[i][j]s shortest possible time from ith to jth street or is it just the time taken by direct roads from ith to jth street???

nothing wrong with test

abhinav1592 @ 1 Aug 2012 05:08 PM
nothing wrong with test cases...suneetk92 & atanu1991 )) read the problem statement carefully...

@pratikjain1993 - If t[i][j]

manonmission @ 1 Aug 2012 05:10 PM
@pratikjain1993 - If t[i][j] is the shortest possible time then the answer in case 3 1 2 will be 5 4 and not 3 2 .

@Admin My code is running

ajit_a @ 1 Aug 2012 05:18 PM
@Admin My code is running perfectly on my machine but here I am getting RTE. Can you please tell the issue ?

@admin can the "saved time"

ocozalp @ 1 Aug 2012 05:30 PM
@admin can the "saved time" value be negative?

@admin my code getting

akash2504 @ 1 Aug 2012 07:32 PM
@admin my code getting runtime error but works perfectly fine on online compiler ideone can u please go through it?

T[i][j] > 0 for i not equal

vonka @ 1 Aug 2012 08:15 PM
T[i][j] > 0 for i not equal to j can i assume this?

Please someone clarify test

kuruma @ 1 Aug 2012 09:13 PM
Please someone clarify test case 3 1 2 and explain how it outputs 3 2, because according to my understanding of the statement, that test case is not correct

@mihsathe- since i,j will

avenger_coder @ 1 Aug 2012 10:18 PM
@mihsathe- since i,j will vary from 0 to N-1.. so u can easily think of limits of i and j,

foul!!!! kuruma solving it in

makandriaco @ 1 Aug 2012 10:33 PM
foul!!!! kuruma solving it in comments????

@kuruma: then whats the point

dummysg @ 1 Aug 2012 10:46 PM
@kuruma: then whats the point of having the matrix(T)?? I think what u r proposing is wrong!

@makandriaco I am not solving

kuruma @ 1 Aug 2012 11:41 PM
@makandriaco I am not solving anything I'm just clearing the answer for the 3rd test case... @dummysg The shortest path mentioned in the statement is related to the matrix... Please work on the test cases yourself, as I don't want to be accused of giving any solution away here...As that is not the point :)))

@ocozalp: It can't be...it

pratikjain1993 @ 2 Aug 2012 12:52 AM
@ocozalp: It can't be...it must be greater than or equal to zero...u can prove it very easily....

I am not able to understand

stalin @ 2 Aug 2012 02:41 AM
I am not able to understand what SGD represent.. please someone explain any one of test cases.. ex: 0 2 1. It means S=0, G=2, D=1; then how to travel ..!?

The time limit says 1sec ,

premprakash90 @ 2 Aug 2012 05:31 AM
The time limit says 1sec , but solutions with time limit > 1sec are accepted .

for the test case 3 1 2 even

azmathbasha @ 2 Aug 2012 08:17 AM
for the test case 3 1 2 even the shortest path is also 5 4

T[i][j] can be 0 even if i !=

hiroto_adm @ 2 Aug 2012 12:37 PM
T[i][j] can be 0 even if i != j. And T[i][j] must be 0 if i = j.

A lot of people are

vamsi_adm @ 2 Aug 2012 01:20 PM
A lot of people are discussing test cases and giving an explanation for the sample cases in the comments. This is NOT allowed during a contest. Whatever explanation is needed to solve the problem, has been provided in the problem statement. Please do NOT post hints/solutions/explanations here.

@kuruma you were explaining

makandriaco @ 2 Aug 2012 11:56 PM
@kuruma you were explaining the case. post got deleted

can anybody explain me the

jomblick @ 3 Aug 2012 12:17 AM
can anybody explain me the matrix T?

>1s accepted

drpaulvazo @ 3 Aug 2012 01:43 AM
>1s accepted

please provide some more test

ankitratnam @ 3 Aug 2012 06:13 PM
please provide some more test cases/hints because I am getting correct output for above given test case but still WA.

can the boy take a path

georgejsh @ 4 Aug 2012 01:23 AM
can the boy take a path through the source aftr he fills the gas???

Frustrating.. Everything

anubhav17 @ 4 Aug 2012 01:50 AM
Frustrating.. Everything seems to be fine with my solution, still getting WA.. :( Stuck at some crappy corner case.. :x

It will be better if details

akasonu @ 4 Aug 2012 02:27 AM
It will be better if details of run time error was shown. Would have helped where am I stuck? Memory segmentation or Exceptions or something else.

M is more than 10000. use

paragagrawal11 @ 4 Aug 2012 08:11 AM
M is more than 10000. use long long int for M.

I am new to codechef. I am

anandveeramani @ 4 Aug 2012 10:43 AM
I am new to codechef. I am getting runtime error but the example test passes fine. Is there a way to debug such kind of stuff? Memory takes 10.8M, time take 0.38 secs. In the mail I got SIGSEGV (segmentation fault) but I recehcked my code for such things I am not accessing outside limits. Can I know which test case I am getting runtime error? Is there way in this codechef system.

@anandveeramani : Nope, you

squeezethekey @ 4 Aug 2012 03:07 PM
@anandveeramani : Nope, you have to do it yourself. Don't worry if you keep getting it wrong. Once the competition ends the solutions will be available to you to find your mistake and improve yourself.

Hi, in the languages listed,

winny_gupta @ 4 Aug 2012 08:01 PM
Hi, in the languages listed, I could not find C#. Can I still submit the code in C# and it will be successfull ?

This is an interesting

monni_suresh @ 5 Aug 2012 12:50 AM
This is an interesting question.

can anyone clearly explain

sdurgi @ 5 Aug 2012 02:08 AM
can anyone clearly explain why the ans to the test case '3 1 2' is not ' 5 4' but ' 3 2'

does the boy take the

shilpi__singh @ 5 Aug 2012 04:55 PM
does the boy take the shortest path from source to destination which has gas station in its way OR the shortest path from source to gas station and then the shortest path from gas station to destination.?

@ drpaulvazo : are you sure

ajayram @ 5 Aug 2012 06:02 PM
@ drpaulvazo : are you sure that > 1s is accepted ? Beacuse my code is giving TLE...

@admin can i get all the set

diveshdixit @ 6 Aug 2012 12:57 AM
@admin can i get all the set of inputs test in text file, i am getting runtime error in java.. may be arrayOutOfBound Exception. the above one test case is working fine... but how to debug for others ???

the test case 3 1 2 seems to

logical_coder @ 6 Aug 2012 12:49 PM
the test case 3 1 2 seems to be wrong ... can someone help!!!!!

@Admin, I an repeatidely

ajit_a @ 6 Aug 2012 05:57 PM
@Admin, I an repeatidely getting WA. May I know one thing that does all the answers need to be correct for the code to be accepted ?. If yes, then on what basis Accuracy is calculated ?

The hell is wrong with the

elmagnifico @ 6 Aug 2012 07:16 PM
The hell is wrong with the judge?? Declaration of DDA inside main() results in TLE.. Global declaration is accepted.. o.O o.O o.O

nooooooo, python solution get

aropan @ 7 Aug 2012 04:38 AM
nooooooo, python solution get TL((

Easy problem, but my solution

resurgent @ 7 Aug 2012 07:26 PM
Easy problem, but my solution gets WA.. Can't understand >_<

2 0 1 0 (3) 2 3 2 the

sumitsah311 @ 7 Aug 2012 10:32 PM
2 0 1 0 (3) 2 3 2 the output in the bracket is wrong...

@Admin: whats going on for

manoharsingh23 @ 8 Aug 2012 07:27 AM
@Admin: whats going on for this problem don't kno.. compilation errror compilation error... bt what the hell is that compilation error??? neither showing nor accepting the solution.... plz check http://www.codechef.com/view/AUG12/error/1233891/

i wrote a code for this

sonuk7 @ 9 Aug 2012 12:40 AM
i wrote a code for this program...and test with the sample of code written still it's show me wrong answer why so??

apply the shortest path

nikhil1265 @ 11 Aug 2012 01:12 AM
apply the shortest path algorithm....and the problem is done...

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.