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

Method tarjan2

src/class196/Code01_2SAT1.java:89–128  ·  view source on GitHub ↗
(int node)

Source from the content-addressed store, hash-verified

87
88 // 迭代版
89 public static void tarjan2(int node) {
90 stacksize = 0;
91 push(node, -1, -1);
92 int v;
93 while (stacksize > 0) {
94 pop();
95 if (status == -1) {
96 dfn[u] = low[u] = ++cntd;
97 sta[++top] = u;
98 e = head[u];
99 } else {
100 v = to[e];
101 if (status == 0) {
102 low[u] = Math.min(low[u], low[v]);
103 }
104 if (status == 1 && belong[v] == 0) {
105 low[u] = Math.min(low[u], dfn[v]);
106 }
107 e = nxt[e];
108 }
109 if (e != 0) {
110 v = to[e];
111 if (dfn[v] == 0) {
112 push(u, 0, e);
113 push(v, -1, -1);
114 } else {
115 push(u, 1, e);
116 }
117 } else {
118 if (dfn[u] == low[u]) {
119 sccCnt++;
120 int pop;
121 do {
122 pop = sta[top--];
123 belong[pop] = sccCnt;
124 } while (pop != u);
125 }
126 }
127 }
128 }
129
130 public static void main(String[] args) throws Exception {
131 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