MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / dfs2

Method dfs2

src/class199/Code04_RingRoad1.java:80–108  ·  view source on GitHub ↗
(int cur)

Source from the content-addressed store, hash-verified

78
79 // 迭代版
80 public static void dfs2(int cur) {
81 stacksize = 0;
82 push(cur, -1, 0, -1);
83 int v;
84 while (stacksize > 0) {
85 pop();
86 if (status == -1) {
87 dfn[u] = ++cntd;
88 e = head[u];
89 } else {
90 v = to[e];
91 if (status == 1 && dfn[u] < dfn[v]) {
92 x = u;
93 y = v;
94 skip = (e + 1) >> 1;
95 }
96 e = nxt[e];
97 }
98 if (e != 0) {
99 v = to[e];
100 if (dfn[v] == 0) {
101 push(u, 0, 0, e);
102 push(v, -1, 0, -1);
103 } else {
104 push(u, 1, 0, e);
105 }
106 }
107 }
108 }
109
110 // 递归版
111 public static void dpOnTree1(int u, int fa) {

Callers 1

computeMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected