Basic
Last updated
Last updated
enum State {
UNVISITED, VISITED
}
class Node {
State state = State.UNVISITED;
List<Node> neighbors;
}
private void DFSMarkVisistedOne(Node v) {
if (v.state == State.VISITED) {
return;
}
v.state = VISITED;
for (Node nei: v.neighbors) {
DFSMarkVisitedOne(nei);
}
}enum State {
UNVISITED, VISITED
}
class Node {
State state = State.UNVISITED;
List<Node> neighbors;
}
private void DFSMarkVisitedThree(Node v) {
if (v.state == State.VISITED) {
return;
}
v.state = VISITED;
for (Node nei: v.neighbors) {
DFSMarkVisitedThree(nei);
}
v.state = UNVISITED;
}//psudo code: return type:在这个分支下,能不能找到解
private boolean DFS() {
if () {
return true;
}
for (all branches) {
if (DFS(this branch) == true) {
return true;
}
}
return false;
}
enum State {
UNVISITED, VISITED
}
class Node {
State state = State.UNVISITED;
List<Node> neighbors;
}
private boolean DFSMarkVisitedThree(Node v) {
if (v.state == State.VISITED) {
return false;
}
if (condition reached) {
return true;
}
v.state = VISITED;
for (Node nei: v.neighbors) {
if (DFSMarkVisitedThree(nei)) {
return true;
}
}
v.state = UNVISITED;
return false;
}