A bit rusty on it. What about Dijkstra?
Boolean[] visited; // [node] = true; Boolean[][] connected; // [node][i] = node Vector<Vector<Integer>>[] path; // this should suck Integer startNode; Integer endNode; Queue queue0; //for thread 0 Queue queue1; //for thread 1 while (queue0.hasNext()) { Integer node = queue.getNext(); if visited[node] { continue; } else { visited[node] = true; } for (nextNode: connected[node]) { for (i) { path[nextNode].append(path[node][i].clone().append(node)); } if (nextNode%2 == 0) { queue0.add(nextNode); } if (nextNode%2 == 1) { queue1.add(nextNode); } } }
path [endNode] [i] // i-th path to endNode from startNode
splitting: came from node% 2
subtasks: find a place to go from node
association: you have a common memory, right?
please delete me
source share