Philosophi's blog

By Philosophi, history, 12 months ago, In English

Hi everyone, I am recently solving this problem and my code is here. Can anyone tell me why i can not pass the 9th test ? thank you so much !!!

  • Vote: I like it
  • +2
  • Vote: I do not like it

»
12 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

Your Dijkstra is implemented wrong:

 1 while(!pq.empty()){
 2     auto temp = pq.top();
 3     ll u = get<1>(temp);
 4     ll half = get<2>(temp);
 5     pq.pop();
 
 6     for(auto p: edge[u]){
 7        ll v = p.first;
 8        ll w = (half ? p.second / 2 : p.second);
 9        bool nex = half | check[v];
10        if(dis[type][v][nex] > dis[type][u][half] + w){
11            dis[type][v][nex] = dis[type][u][half] + w;
12            pq.emplace(-dis[type][v][nex], v, nex);
13         }
14     }
15 }

It's possible that for any given vertex $$$v$$$ and horse thing $$$half$$$, multiple triples $$$(dist, v, half)$$$ get pushed into the priority queue — the cheapest one and ones that the algorithm discovered before that. Each of these triples is eventually popped from the priority queue, and thus for each vertex, we look at its outgoing edges many times, not just once as Dijkstra is supposed to work.