Skip to content

Commit 094baf3

Browse files
authored
修正了堆操作的错误
1 parent 851eddf commit 094baf3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Dijkstra(Heap-Optimised).cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#define INF 1000000000
44

5-
#define VERTEX_COUNT 100000
6-
#define EDGE_COUNT 100000
5+
#define VERTEX_COUNT 100010
6+
#define EDGE_COUNT 1000010
77

88
using namespace std;
99

@@ -86,20 +86,23 @@ void heap_sink(int i)
8686
void heap_float(int i)
8787
{
8888
int p = i >> 1;
89-
while (i > 1 && V[H[i]].dis < V[H[p]].dis)
89+
while (p > 1 && V[H[i]].dis < V[H[p]].dis)
9090
{
9191
pos[H[i]] = p;
9292
pos[H[p]] = i;
9393
int temp = H[i];
9494
H[i] = H[p];
9595
H[p] = temp;
96+
i = p;
97+
p = i >> 1;
9698
}
9799
}
98100

99101
int extract_min()
100102
{
101103
int res = H[1];
102104
H[1] = H[heapsize--];
105+
pos[H[1]] = 1;
103106
heap_sink(1);
104107
return res;
105108
}

0 commit comments

Comments
 (0)