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

Method tarjan2

src/class196/Code06_Riddle1.java:111–150  ·  view source on GitHub ↗
(int node)

Source from the content-addressed store, hash-verified

109
110 // 迭代版
111 public static void tarjan2(int node) {
112 stacksize = 0;
113 push(node, -1, -1);
114 int v;
115 while (stacksize > 0) {
116 pop();
117 if (status == -1) {
118 dfn[u] = low[u] = ++cntd;
119 sta[++top] = u;
120 e = head[u];
121 } else {
122 v = to[e];
123 if (status == 0) {
124 low[u] = Math.min(low[u], low[v]);
125 }
126 if (status == 1 && belong[v] == 0) {
127 low[u] = Math.min(low[u], dfn[v]);
128 }
129 e = nxt[e];
130 }
131 if (e != 0) {
132 v = to[e];
133 if (dfn[v] == 0) {
134 push(u, 0, e);
135 push(v, -1, -1);
136 } else {
137 push(u, 1, e);
138 }
139 } else {
140 if (dfn[u] == low[u]) {
141 sccCnt++;
142 int pop;
143 do {
144 pop = sta[top--];
145 belong[pop] = sccCnt;
146 } while (pop != u);
147 }
148 }
149 }
150 }
151
152 public static void main(String[] args) throws Exception {
153 FastReader in = new FastReader(System.in);

Callers 1

mainMethod · 0.95

Calls 2

pushMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected