https://cses.fi/problemset/task/1671/
I m getting tle in only 2 test cases of this problem. here's my code link--
need help!!****
https://cses.fi/problemset/task/1671/
I m getting tle in only 2 test cases of this problem. here's my code link--
need help!!****
# | User | Rating |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
4 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Name |
---|
Your use of vis[] is not correct.
if (!vis[v]&&dist[v] > dist[u] + weight)
Just remove it. It is enough to check if dist[v] can be relaxed. This is the case if a longer path is cheaper because sum of weights are less than a earlier, shorter path.
okay..but still giving tle. thanks for replying spookywooky
Sorry, I was wrong ;)
You need a vis[] array here. But not inside the loop over the children. You should check vis[] array just after pop() from the queue.
Since it is a priority_queue, the first time a node is popped from the queue the path is shortest, so all pops after the first one can be ignored.
Just write this line "if(dist[u]<w)continue;" before the for loop in shortestpath function, here "w=pq.top().first".
AC..thanks a lot man! can you explain about it little bit (if possible).-Baba_Yaga
You can read about it from here http://e-maxx.ru/algo/dijkstra_sparse.