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 Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » March 2011 Challenge » The Amazing All-In-One Cooking Machine - Challenge

The Amazing All-In-One Cooking Machine - Challenge

Problem code: ALLINONE

  • All Submissions

All submissions for this problem are available.

The Chef has recently sold a number of his amazing all-in-one cooking machines! These machines can be used to prepare virtually any recipe you want. Unfortunately, there seems to be a major flaw in many of these devices.

The problem can be fixed very quickly with the right replacement part (it takes essentially 0 time). Since the Chef endorsed these devices so much, he takes it upon himself to perform all of the repairs. He has a list of clients that need their devices repaired as well as a map of the city so he can find the most efficient route between any two clients.

The Chef wants to repair these devices as fast as possible. However, since customer satisfaction is very important, his goal is to visit the clients in some order that minimizes the average time each client waits to be served. Specifically, we let T(i) denote the amount of time it takes for the Chef to reach client i from the moment he starts traveling given that he visits all clients that appear before client i on the list in the given order. Then the Chef's goal is to minimize the average of the waiting times, which is (T(1) + T(2) + ... + T(k))/k if there are k clients.

Input

The first line contains a single positive integer T ? 30 indicating the number of test cases to follow. Each test case begins with three integers N, M and K written on a single line. Here, N is the number of intersections in the city, K is the number of clients and M is the number of streets to follow. The intersections are numbered from 0 to N-1 and the Chef begins at intersection 0.

Following this is a single line containing K integers describing the locations of the clients. The i'th such integer (between 1 and N-1) indicates the intersection where the i'th client resides. Note that any particular intersection may contain more than one client. Note also that no clients are located at intersection 0.

Then M lines follow, each describing a street. A street is given by three integers U,V, and D where U,V are distinct integers between 0 and N-1 describing the endpoints of the street and D is a positive integer that indicates how long it takes to travel from U to V along this road. No two intersections will be the endpoint of more than one road. Furthermore, it will always be possible reach all clients from intersection 0.

Bounds: 2 ? N ? 300, 1 ? K ? 10000, and 1 ? M ? 2000. Furthermore, each street distance D is between 1 and 1000.

Output

For each test case you are to output a permutation of the integers from 1 to K on a single line. This is the order in which the Chef will visit the clients. It does not need to be optimal, any permutation from 1 to K will be accepted. However, your goal should be to try and make the average waiting times of the clients as small as you possibly can in your solution. Your solution will be scored according to the following scoring mechanism.

Scoring

Starting from intersection 0, the Chef will visit these clients in the order they appear in the output. If we define T(0) = 0, then the time it takes to reach client i ? 1, say T(i), is precisely T(i-1) plus the shortest time that the Chef can reach the intersection containing client i in this list from the intersection containing client i-1 in this list. The score for a particular test case is then (T(1) + T(2) + ... + T(K))/K. The overall score over all test cases in a test file is simply the sum of the scores of each individual test case.

Example

Input:
3
4 3 3
1 2 3
0 1 1
0 2 10
1 3 100
5 6 10
1 2 3 2 3 4 3 2 3 2
0 1 2
0 2 4
0 3 3
3 4 2
4 2 1
2 1 1
3 2 10
1 1 1 1 1 1 1 1 1 2
0 1 5
0 2 1


Output:
1 3 2
2 4 8 10 3 5 7 9 1 6
1 2 3 4 5 6 7 8 9 10

Explanation of Sample Data

The optimal solution for the first test case is actually 1 2 3, but 1 3 2 is a valid ordering according to the problem description so it is accepted. Client 1 only waits 1 unit of time to be served. The time to travel from client 1 to client 3 is 100 units of time so client 3 must wait a total of 101 units of time to be served. Then, traveling from client 3 to client 2 takes 111 units of time so client 2 waits a total of 212 units of time to be served. Thus, the average amount of time it takes for a client to be served is then (1 + 101 + 212)/3 = 314/3 and that will be the score for the output on this test case.

The other two test cases are analyzed similarly. In the third test case, all of the clients at location 1 are visited first. It takes 5 units of time to travel to location 1 and serve the first client. However, since we assume it takes 0 time to serve a client we can take care of the rest of the clients at location 1 immediately. So, each client at location 1 waited only 5 units of time to be served meaning the total time waited by all clients at this location is 45 units. Finally, it takes 6 units of time to travel to the sole client at location 2 so the average time waited by the clients is then 56/10.

Overall, the score for the entire set of data (being the sum of the scores of individual test cases) is 116.066667.

Test Data

Some test data has been hand crafted to make certain heuristics perform poorly and some has been generated randomly from a variety of distributions.


Author: friggstad
Date Added: 7-02-2011
Time Limit: 8 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


  • Submit

Comments

  • Login or Register to post a comment.

Are the streets

balajiganapath @ 1 Mar 2011 04:47 PM

Are the streets bidirectional?

Is there posibility of having

Arun07 @ 1 Mar 2011 07:52 PM

Is there posibility of having no client at an intersection other than 0 ?

@ Balajiganapathi Yes, the

zac_adm @ 1 Mar 2011 09:28 PM

@ Balajiganapathi

Yes, the streets are bidirectional.

@ Arun Saini

Please read the input description carefully.

why the ans of first case is

cooltodinesh @ 1 Mar 2011 11:52 PM

why the ans of first case is not

2 1 3 ?

this gives average (10+11+121)/3 which is far less than 314/3.

Please help me to understand question.

sorry i mean (10+21+121)/3

cooltodinesh @ 1 Mar 2011 11:54 PM

sorry i mean (10+21+121)/3

@ Dinesh This is a challenge

zac_adm @ 2 Mar 2011 01:48 AM

@ Dinesh

This is a challenge problem meaning all you have to do is output any solution that conforms to the output specification. If your solution is valid, then you will be assigned a score based on the scoring mechanism outlined in the description. Suboptimal solutions are accepted (as long as they are valid), they just won't get the lowest possible score.

The optimal solution for the

shashankneocfc @ 2 Mar 2011 02:38 AM

The optimal solution for the first test case is actually 1 2 3, but 1 3 2 is a valid ordering according to the problem description so it is accepted.

 

I'm not able to understand that part.Possibly it have to do with this part of the question."he starts traveling given that he visits all clients that appear before client i on the list in the given order." . Please shed more light onto this segment,

@ Shashank Jain - All problem

yellow_agony @ 3 Mar 2011 11:00 PM

@ Shashank Jain - All problem statement is saying is this  : Given permutation of [1..K] as T(1) ... T(K), chef moves as follows :

First from 0 to T[1] along shortest possible path. Then from T[1] to T[2] along shortest path and so on.

So when chef reaches T[i], time for which ith client has been waiting is time taken in tour from 0 to T[i-1] via all intermediate vertices. We need to find average of this waiting time.

Is the graph guarenteed to be

utkarsh_lath @ 10 Mar 2011 10:41 AM

Is the graph guarenteed to be planar, as the context suggests ?

@ utkarsh lath Nope. In

zac_adm @ 11 Mar 2011 12:12 AM

@ utkarsh lath

Nope. In general, such a graph in a real-world city is not necessarily planar because of overpasses. I bet it is easy to find a K_5 minor (which cannot exist in a planar graph) in a large city with lots of overpasses :)

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
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.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com