I am getting Memory limit exceeded for this problem C. Dijkstra? But why I can not understand this. My Solution
№ | Пользователь | Рейтинг |
---|---|---|
1 | ecnerwala | 3649 |
2 | Benq | 3581 |
3 | orzdevinwang | 3570 |
4 | Geothermal | 3569 |
4 | cnnfls_csy | 3569 |
6 | tourist | 3565 |
7 | maroonrk | 3531 |
8 | Radewoosh | 3521 |
9 | Um_nik | 3482 |
10 | jiangly | 3468 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 161 |
4 | TheScrasse | 159 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
I am getting Memory limit exceeded for this problem C. Dijkstra? But why I can not understand this. My Solution
Название |
---|
The size of queue is getting very large during execution you can either use set like this solution and clear the entry for v line number 29 this will restrict the size of set to at max O(N) http://codeforces.com/contest/20/submission/43596615
or like this solution you can free some memory by clearing the vectors you are not going to use. http://codeforces.com/contest/20/submission/43596568
But I can not understand how the set (is it work like priority queue ? )work in here please can you explain it .
the purpose of priority queue is to extract the minimum element. In set the 1st element is the smallest element. While set provide an option to erase a element while the same operation is not supported in priority queue. priority queue is implemented as Heap while set is implemented as red black tree(Binary search tree)
Ok that's great I understood now thank you .
Actually, set has higher overhead compared to priority queue due to additional book-keeping such as balancing. In this case, blue__legend was able to achieve a much better runtime and memory limit because of the fact that we can efficiently search for and remove irrelevant nodes from the set, whereas we can't do so in a priority queue.
Anyway, I think that your main problem is that you didn't terminate your loop, in your dijkstra shortest path implementation, when your destination has been visited. As such, a lot of irrelevant nodes might be stored in the priority queue and cause the MLE to occur.
Since your are using int as a distance it overflows and turn into negative number, that is why you are getting memory limit exceeded. try it by changing into long long