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
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Code Baker » Courier

Courier

Problem code: DCE02

  • All Submissions

The ship Titanic is very huge. It is often required by the staff to take things from 1 place to other.
Given the cost of possible paths through different levels, return the minimum cost of the path taken from the top level to the bottom level. ( It is not necessary that all the sectors are connected. There will always be a path from topmost level to lowest level. )

Input

The first line contains two space separated integers n, k. Where n is the number of sectors on the topmost level, and k is the number of levels in the ship.
From the next line onwards, three space separated integers are given. First integer is the starting sector from 1st level, 2nd integer is the destination in the 2nd level, and 3rd integer is the cost of path. (The sources and destinitions are 1-based)
The integer -1 signifies the end of paths for the given pair of levels.
The next lines contain the paths for next pair of levels till a -1is encountered, and so on.
(So the total number of -1 encountered are k-1)

Output

A single line containing the minimum cost to travel from topmost level to lowest level.

Example

Input:
5 2
1 1 1
2 2 2
1 3 3
3 1 6
5 4 9
-1


Output:
1


Explanation:
There are just two levels. The shortest path is from sector 1 on level 1 to sector 1 on level 2.


Author: uploader0
Date Added: 14-10-2009
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, 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, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Please ignore submissions

sally11 @ 27 Oct 2009 06:18 PM

Please ignore submissions made by Sailesh Mittal.

What are the constraints of

rohil @ 27 Oct 2009 06:52 PM

What are the constraints of different parameters ? Is it possible to move between sectors on same levels (seemingly not, just confirming)? And why is n given ? Isn't n visible while encountering the first -1 itself ? And total cost fits within a 4 byte int , right ?

Thanks

Constraints: n<=1000, k<n. It

sally11 @ 27 Oct 2009 07:16 PM

Constraints: n<=1000, k<n.

It is not possible to move between sectors on same level.

n is not visible while encountering the first -1. There may not be a path from one sector to another in a pair of levels. It may be visible by the number of -1s encountered though.

It is not possible to move

akhil89 @ 27 Oct 2009 07:19 PM

It is not possible to move between sectors on the same level.

n gives the number of sectors on the first level(deck). -1 is encountered when all the edges from a level to the next level are over. The number of edges and number of sectors in a level might not be same.

Other things you have to figure out yourself!

Best of luck!

Sorry but it is still

rohil @ 27 Oct 2009 07:47 PM

Sorry but it is still unclear. The number of -1 is always k-1. So, there will be k-1 sets of edges giving edges b/w 1st and 2nd,2nd and 3rd,....second last to last levels. So, the 1st set automatically tells us which of the relevant sectors in topmost level are there. This is assuming that all triplets of sector1,sector2,cost are valid.

Can you please give an example test case where n is needed ?

@Sailesh

You said that "There may not be a path from one sector to another in a pair of levels. It may be visible by the number of -1s encountered though.". No. of -1 is always k-1 .. so what does this statement mean ?

I guess there is something I am missing totally.

Sorry for the earlier post.

sally11 @ 27 Oct 2009 08:13 PM

Sorry for the earlier post. The no. of -1s only tells the value of k. The n is for the structure of ship. You may ignore it if you dont require it in the solution.

Structure of the ship: A ship

sally11 @ 27 Oct 2009 08:31 PM

Structure of the ship:

A ship is represented in sectors as below:

+ + + + +     
+ + + +
+ + +


n is the number of sectors in the topmost level, k is the number of levels.
The first(topmost) level contains n sectors, 2nd contains n-1 sectors, and the k-th(lowermost) sector contains n-k+1 sectors.

can you please check the

codegambler @ 28 Oct 2009 10:30 AM

can you please check the correctness of test cases i/o.

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 computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various 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 judge accepts solutions in over 35+ programming languages. Online programming was 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 competitions 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 programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

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. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef 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