using System;
using System.Windows.Forms;
namespace GraphMatrixApp
{
public partial class Form1 : Form
{
int[,] matrix;
public Form1()
{
InitializeComponent();
}
private void btnCreate_Click(object sender, EventArgs e)
{
int n = (int)numericUpDown1.Value;
if (n <= 0)
{
listBox2.Items.Add("Введите корректное количество вершин");
return;
}
matrix = new int[n, n];
dataGridView1.ColumnCount = n;
dataGridView1.RowCount = n;
listBox2.Items.Clear();
}
private void btnClear_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
listBox1.Items.Clear();
listBox2.Items.Clear();
}
private void FindIsolatedVertices()
{
int n = matrix.GetLength(0);
for (int i = 0; i < n; i++)
{
bool isolated = true;
for (int j = 0; j < n; j++)
{
if (matrix[i, j] != 0 || matrix[j, i] != 0)
{
isolated = false;
break;
}
}
if (isolated)
listBox1.Items.Add($"Вершина {i} изолирована");
}
}
private void btnCheck_Click(object sender, EventArgs e)
{
try
{
int n = dataGridView1.RowCount;
matrix = new int[n, n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
matrix[i, j] = Convert.ToInt32(dataGridView1[j, i].Value);
}
}
listBox1.Items.Clear();
FindIsolatedVertices();
}
catch
{
listBox2.Items.Add("Ошибка ввода матрицы");
}
}
}
}