You are not logged in. Please login at www.codechef.com to post your questions!

×

Getting TLE in Hackerearth The Parking Slot problem

I am gettign TLE for The Parking Slot problem on hackerearth, here is the link to my code, I have used dijkstra's algorithm.

Help needed in getting AC for this problem.

asked 26 Jun, 09:37

arpit728's gravatar image

2★arpit728
6831462
accept rate: 10%


There was problem in your dijkstra code. You were always pushing into the queue. But you should do that only when needed. Just change this and you get AC.

     if(d[edge.v][DISTANCE]>d[u.v][DISTANCE] + edge.w){
                    d[edge.v][DISTANCE] = Long.min(d[edge.v][DISTANCE], d[u.v][DISTANCE] + edge.w);
                    queue.add(new Edge(edge.v, d[edge.v][DISTANCE]));
                    }
    

link

answered 26 Jun, 11:24

soham1234's gravatar image

6★soham1234
1.8k614
accept rate: 22%

edited 26 Jun, 11:25

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,186
×384
×159

question asked: 26 Jun, 09:37

question was seen: 93 times

last updated: 26 Jun, 11:25