HDOJ 3790 【SPFA】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
while (!q.empty())
{
xx = q.front();
q.pop();
QM[xx] = 0;
for (int i = 1; i <= nNum; ++i)
{
if (dist[i] > dist[xx] + g[xx][i])
{
dist[i] = dist[xx] + g[xx][i];
px[i] = px[xx] + cost[xx][i];
if (QM[i] == 0)
{
QM[i] = 1;
q.push(i);
}
}
else if (dist[i] == dist[xx] + g[xx][i] && px[i] > px[xx] + cost[xx][i])
{
px[i] = px[xx] + cost[xx][i];
}
}
}
文章目录
|