All pastes #813951 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-12-12 22:07 UTC
rendered paste body
void relax1(GraphRef G, int u, int v, PriorityQueueRef Q) {
	if(G->distances[v] > G->distances[u] + G->weights[u][v]) {
		G->distances[v] = G->distances[u] + G->weights[u][v];
		G->parents[v] = u;
		
		if(inQueue(Q, v))
			decreaseKey(Q, v, G->distances[v]);
	}
}

void relax2(GraphRef G, int u, int v) {
	if(G->distances[u] >= INF)
		return;
		
	if(G->distances[v] > G->distances[u] + G->weights[u][v]) {
		G->distances[v] = G->distances[u] + G->weights[u][v];
		G->parents[v] = u;
	}
}