Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
36
Task/Kosaraju/EasyLang/kosaraju.easy
Normal file
36
Task/Kosaraju/EasyLang/kosaraju.easy
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
sysconf zero_based
|
||||
#
|
||||
g[][] = [ [ 1 ] [ 2 ] [ 0 ] [ 1 2 4 ] [ 3 5 ] [ 2 6 ] [ 5 ] [ 4 6 7 ] ]
|
||||
gc = len g[][]
|
||||
len vis[] gc
|
||||
len l[] gc
|
||||
x = gc
|
||||
len t[][] gc
|
||||
proc visit u . .
|
||||
if vis[u] = 0
|
||||
vis[u] = 1
|
||||
for v in g[u][]
|
||||
visit v
|
||||
t[v][] &= u
|
||||
.
|
||||
x -= 1
|
||||
l[x] = u
|
||||
.
|
||||
.
|
||||
for i range0 gc
|
||||
visit i
|
||||
.
|
||||
len c[] gc
|
||||
proc assign u root . .
|
||||
if vis[u] = 1
|
||||
vis[u] = 0
|
||||
c[u] = root
|
||||
for v in t[u][]
|
||||
assign v root
|
||||
.
|
||||
.
|
||||
.
|
||||
for u in l[]
|
||||
assign u u
|
||||
.
|
||||
print c[]
|
||||
92
Task/Kosaraju/FreeBASIC/kosaraju.basic
Normal file
92
Task/Kosaraju/FreeBASIC/kosaraju.basic
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
' Define a custom type for a dynamic array of integers
|
||||
Type IntArray
|
||||
Dato As Integer Ptr
|
||||
Size As Integer
|
||||
End Type
|
||||
|
||||
' Function to add an element to the IntArray
|
||||
Sub AddToIntArray(arr As IntArray Ptr, value As Integer)
|
||||
arr->Size += 1
|
||||
arr->Dato = Reallocate(arr->Dato, arr->Size * Sizeof(Integer))
|
||||
arr->Dato[arr->Size - 1] = value
|
||||
End Sub
|
||||
|
||||
' Define the graph as an array of IntArrays
|
||||
Dim Shared As IntArray g(7)
|
||||
' Global variables for Kosaraju's algorithm
|
||||
Dim Shared As IntArray t(7)
|
||||
Dim Shared As Boolean vis(7)
|
||||
Dim Shared As Integer x, L(7), c(7)
|
||||
|
||||
' Initialize the graph
|
||||
Sub InitGraph()
|
||||
Dim As Integer i, j
|
||||
Dim As Integer edges(7, 3) = {{1},{2},{0},{1,2,4},{3,5},{2,6},{5},{4,6,7}}
|
||||
For i = 0 To 7
|
||||
For j = 0 To 2
|
||||
If edges(i, j) >= 0 Then AddToIntArray(@g(i), edges(i, j))
|
||||
Next
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Sub Visit(u As Integer)
|
||||
If Not vis(u) Then
|
||||
vis(u) = True
|
||||
For i As Integer = 0 To g(u).Size - 1
|
||||
Visit(g(u).Dato[i])
|
||||
AddToIntArray(@t(g(u).Dato[i]), u)
|
||||
Next
|
||||
x -= 1
|
||||
L(x) = u
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Assign(u As Integer, root As Integer)
|
||||
If vis(u) Then
|
||||
vis(u) = False
|
||||
c(u) = root
|
||||
For i As Integer = 0 To t(u).Size - 1
|
||||
Assign(t(u).Dato[i], root)
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Kosaraju(n As Integer)
|
||||
Dim As Integer i
|
||||
' Initialize variables
|
||||
For i = 0 To n-1
|
||||
vis(i) = False
|
||||
t(i).Size = 0
|
||||
If t(i).Dato Then Deallocate(t(i).Dato)
|
||||
Next
|
||||
x = n
|
||||
|
||||
' Visit all vertices
|
||||
For i = 0 To n-1
|
||||
Visit(i)
|
||||
Next
|
||||
|
||||
' Reset visited array
|
||||
For i = 0 To n-1
|
||||
vis(i) = True
|
||||
Next
|
||||
|
||||
' Free temporary arrays
|
||||
For i = 0 To n-1
|
||||
Assign(L(i), L(i))
|
||||
Next
|
||||
End Sub
|
||||
|
||||
InitGraph()
|
||||
Dim n As Integer = 8 ' Number of vertices
|
||||
Kosaraju(n)
|
||||
|
||||
For i As Integer = 0 To n-1
|
||||
' Print the result
|
||||
Print c(i);
|
||||
' Free allocated memory
|
||||
If g(i).Dato Then Deallocate(g(i).Dato)
|
||||
If t(i).Dato Then Deallocate(t(i).Dato)
|
||||
Next
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue