This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void dijkstra() { | |
int[] dist = new int[n + 1]; | |
boolean[] visited = new boolean[n + 1]; | |
for (int source = 0; source < k + 1; source++) { | |
arrays.fill(dist, INFINITY); | |
arrays.fill(visited, false); | |
dist[list[source]] = 0; | |
for (int t = 0; t < n; t++) { | |
int min = INFINITY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memo = new int[V][1 << V]; | |
T = new int[V][V]; // adjacency matrix | |
int min_dist_from_0 = DP_TSP(0, 1); | |
int DP_TSP(int u, int m) { // m is visited mask (bitmask) | |
if (m == ((1 << V) - 1)) // all 1, all vertices have been visited | |
return T[u][0]; // no choice, return to vertex 0 | |
if (memo[u][m] != -1) // computed before | |
return memo[u][m]; |
NewerOlder