Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Tarjan/J/tarjan-1.j
Normal file
36
Task/Tarjan/J/tarjan-1.j
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
tarjan=: {{
|
||||
coerase ([ cocurrent) cocreate'' NB. following =: declarations are temporary, expiring when we finish
|
||||
graph=: y NB. connection matrix of a directed graph
|
||||
result=: stack=: i.index=: 0
|
||||
undef=: #graph
|
||||
lolinks=: indices=: undef"_1 graph
|
||||
onstack=: 0"_1 graph
|
||||
strongconnect=: {{
|
||||
indices=: index y} indices
|
||||
lolinks=: index y} lolinks
|
||||
onstack=: 1 y} onstack
|
||||
stack=: stack,y
|
||||
index=: index+1
|
||||
for_w. y{::graph do.
|
||||
if. undef = w{indices do.
|
||||
strongconnect w
|
||||
lolinks=: (<./lolinks{~y,w) y} lolinks
|
||||
elseif. w{onstack do.
|
||||
lolinks=: (<./lolinks{~y,w) y} lolinks
|
||||
end.
|
||||
end.
|
||||
if. lolinks =&(y&{) indices do.
|
||||
loc=. stack i. y
|
||||
component=. loc }. stack
|
||||
onstack=: 0 component} onstack
|
||||
result=: result,<component
|
||||
stack=: loc {. stack
|
||||
end.
|
||||
}}
|
||||
for_Y. i.#graph do.
|
||||
if. undef=Y{indices do.
|
||||
strongconnect Y
|
||||
end.
|
||||
end.
|
||||
result
|
||||
}}
|
||||
4
Task/Tarjan/J/tarjan-2.j
Normal file
4
Task/Tarjan/J/tarjan-2.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
tarjan 1;2;0;1 2 4;3 5;2 6;5;4 6 7
|
||||
┌─────┬───┬───┬─┐
|
||||
│0 1 2│5 6│3 4│7│
|
||||
└─────┴───┴───┴─┘
|
||||
Loading…
Add table
Add a link
Reference in a new issue