Dim visited (1 To 6) As Boolean
Dim u, v As Integer
Dim i As Integer, k As Integer
g (1, 1) = 0: g (1, 2) = 1: g (1, 3) = 1: g (1, 4) = 0: g (1, 5) = 0: g (1, 6 ) = 0:
g (2, 1) = 1: g (2, 2) = 0: g (2, 3) = 0: g (2, 4) = 1: g (2, 5) = 1: g (2, 6 ) = 0:
g (3, 1) = 1: g (3, 2) = 0: g (3, 3) = 0: g (3, 4) = 0: g (3, 5) = 0: g (3, 6 ) = 1:
g (4, 1) = 0: g (4, 2) = 1: g (4, 3) = 0: g (4, 4) = 0: g (4, 5) = 0: g (4, 6 ) = 0:
g (5, 1) = 0: g (5, 2) = 1: g (5, 3) = 0: g (5, 4) = 0: g (5, 5) = 0: g (5, 6 ) = 0:
g (6, 1) = 0: g (6, 2) = 0: g (6, 3) = 1: g (6, 4) = 0: g (6, 5) = 0: g (6, 6 ) = 0:
For i = 1 To 6
visited (i) = False
Next i
Call dfs (1, g)
For i = 1 To 6
Print visited (i); "";
Next i
Print
End Sub
Sub dfs (u, g)
Dim visited (1 To 6) As Boolean
visited (u) = True
For k = 1 To 6
If g (u, k) = 1 Then
v = k
If visited (v) = faulse Then
Call dfs (v, g)
End If
End If
Next k
End Sub |