Tarjan algorithm Template

Source: Internet
Author: User
VaR {left indicates that the vertex root has not left the stack. vis indicates whether the vertex root has been accessed} I, n, m, now, time, color, top: longint; V: array [0 .. 10001] of record start: longint; end; E: array [0 .. 100001] of record y, next: longint; end; dfn, low, stack, encolor: array [0 .. 10001] of longint; vis, left: array [0 .. 10001] of Boolean; Procedure indata; var I, XX, YY, OP: longint; begin time: = 0; color: = 0; top: = 0; fillchar (E, sizeof (E), 0); fillchar (v, sizeof (V), 0); fillchar (dfn, sizeof (dfn), 0); fillchar (low, sizeof (low), 0); fillchar (VIS, sizeof (VIS), 0); fillchar (left, sizeof (left), 1); fillchar (encolor, sizeof (encolor), 0); end; Procedure Tarjan (root: longint); var te, TV, ttimes: longint; begin Inc (time); dfn [root]: = time; low [root]: = time; Inc (top); stack [Top]: = root; {point root to stack} left [root]: = false; vis [root]: = true; Te: = V [root]. start; while (te <> 0) Do begin TV: = E [Te]. y; if not left [TV] Then low [root]: = min (low [root], dfn [TV]); if not vis [TV] Then begin Tarjan (TV); low [root]: = min (low [root], low [TV]); end; Te: = E [Te]. next; end; If (dfn [root] = low [root]) then begin Inc (color); TV: = 0; while (TV <> root) Do begin TV: = stack [Top]; Dec (top); encolor [TV]: = color; left [TV]: = true; end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.