手工栈样板
这是tarjan找环的手工栈, 当作样板, 可以照着打QuQ
1 int lev2; 2 3 int st_i2[N],st_x2[N],st_y2[N],st_t2[N]; 4 5 #define i st_i2[lev2] 6 #define y st_y2[lev2] 7 #define x st_x2[lev2] 8 #define nt st_t2[lev2] 9 10 void dfs(int u, int last) { 11 lev2 = 1; 12 st_x2[1] = u; st_y2[1] = last; 13 start:; 14 dfn[x] = ++sz; 15 for(i = head[x]; i; i = e[i].nxt) { 16 nt = e[i].to; 17 if(i == ch(y)) continue; 18 if(dfn[nt]) { 19 if(dfn[nt] < dfn[x]) continue; 20 cur.push_back(x); mk[x] = 1; 21 for(; nt != x; nt = pre[nt]) mk[nt] = 1, cur.push_back(nt); 22 continue; 23 } 24 pre[nt] = x; 25 st_x2[lev2 + 1] = nt; 26 st_y2[lev2 + 1] = i; 27 lev2++; 28 goto start; 29 end:; 30 } 31 lev2--; 32 if(lev2) goto end; 33 } 34 35 #undef i 36 #undef y 37 #undef x 38 #undef nt