Вот решение на VB.NET помогите только перевести в Делфи. Буду очень благодарен!
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim v, r As Integer
Dim matr(100, 100) As Integer
Dim a, b, x As Integer
'Заполняем матрицу смежности и считаем количество вершин'
Dim s As String
For i = 0 To TextBox1.Lines.Count - 1
s = TextBox1.Lines(i)
s = s.Trim()
If s <> "" Then
x = s.IndexOf(" ")
a = Val(s.Substring(0, x))
b = Val(s.Substring(x + 1, s.Length - x - 1))
matr(a, ^_^ = 1
matr(b, a) = 1
If a > v Then v = a
If b > v Then v = b
End If
Next
r = 0
For i = 1 To v
For j = 1 To v
If matr(i, j) = 1 Then r = r + 1
Next
Next
r = r / 2
TextBox2.Text = ""
For i = 1 To v
For j = 1 To v
TextBox2.Text += Str(matr(i, j)) + " "
Next
TextBox2.Text += vbNewLine
Next
TextBox3.Text = Str(v)
TextBox4.Text = Str®
End Sub
End Class