Форум программистов, компьютерный форум, киберфорум
C# Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/6: Рейтинг темы: голосов - 6, средняя оценка - 5.00
0 / 0 / 0
Регистрация: 07.12.2016
Сообщений: 24
1

Определить, существует ли в графе две вершины степени 3 с количеством вершин не менее 4-х смежные между собой

05.12.2018, 15:10. Показов 1173. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте, нужна помощь с графами
Вот задача:
1. Определить, существует ли в графе две вершины степени 3 с количеством вершин не менее 4-х смежные между собой.
Реализовать ее на С#(по нажатию кнопки)

Вот сама программа с графами : https://my-files.ru/17c7vw
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
05.12.2018, 15:10
Ответы с готовыми решениями:

Определить смежные вершины к вершине Е в графе, заданном матрицей смежности
Определить смежные вершины к вершине Е в графе, заданном матрицей смежности: ***** A B C D E A 0...

Смежные вершины в ориентированном графе
Какие вершины называются смежными в ориентированном графе?

Как определить, связны ли две вершины в графе?
Доброго времени суток! Подскажите пожалуйста алгоритм, который смог бы определить, связны ли две...

Эффективный алгоритм подсчета расстояний от произвольной вершины до всех стальных вершин в графе
Реализовать в виде программы и исследовать эффективный алгоритм подсчета расстояний от произвольной...

1
0 / 0 / 0
Регистрация: 07.12.2016
Сообщений: 24
11.12.2018, 18:12  [ТС] 2
Здравствуйте!

Есть программа которая рисует графы. Нужно Определить, существует ли в графе две вершины степени 3 с количеством вершин не менее 4-х смежные между собой.

вот код
класс Graph.cs
Кликните здесь для просмотра всего текста
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace MathGraph
{
    class Vertex
    {
        public int x, y;
 
        public Vertex(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }
 
    class Edge
    {
        public int v1, v2;
        public int Weight;
 
        public Edge(int v1, int v2, int Weight)
        {
            this.v1 = v1;
            this.v2 = v2;
            this.Weight = Weight;
        }
    }
 
    class DrawGraph
    {
        Bitmap bitmap;
        Pen blackPen;
        Pen redPen;
        Pen darkGoldPen;
        Graphics gr;
        Font fo;
        Brush br;
        PointF point;
        public int R = 15; //Радиус окружности вершины
 
        public DrawGraph(int width, int height)
        {
            bitmap = new Bitmap(width, height);
            gr = Graphics.FromImage(bitmap);
            clearSheet();
            blackPen = new Pen(Color.Black);
            blackPen.Width = 2;
            redPen = new Pen(Color.Red);
            redPen.Width = 2;
            darkGoldPen = new Pen(Color.DarkGoldenrod);
            darkGoldPen.Width = 2;
            fo = new Font("Times New Roman", 15);
            br = Brushes.Black;
        }
 
        public Bitmap GetBitmap()
        {
            return bitmap;
        }
 
        public void clearSheet()
        {
            gr.Clear(Color.White);
        }
 
        public void drawVertex(int x, int y, string number)
        {
            gr.FillEllipse(Brushes.White, (x - R), (y - R), 2 * R, 2 * R);
            gr.DrawEllipse(blackPen, (x - R), (y - R), 2 * R, 2 * R);
            point = new PointF(x - 9, y - 9);
            gr.DrawString(number, fo, br, point);
        }
 
        public void drawSelectedVertex(int x, int y)
        {
            gr.DrawEllipse(redPen, (x - R), (y - R), 2 * R, 2 * R);
        }
 
        public void drawEdge(Vertex V1, Vertex V2, Edge E, int numberE, int Weight)
        {
            if (E.v1 == E.v2)
            {
                gr.DrawArc(darkGoldPen, (V1.x - 2 * R), (V1.y - 2 * R), 2 * R, 2 * R, 90, 270);
                point = new PointF(V1.x - (int)(2.75 * R), V1.y - (int)(2.75 * R));
                gr.DrawString(((Weight).ToString() + ":" + (char)('a' + numberE)).ToString(), fo, br, point);
 
                drawVertex(V1.x, V1.y, (E.v1 + 1).ToString());
            }
            else
            {
                gr.DrawLine(darkGoldPen, V1.x, V1.y, V2.x, V2.y);
                point = new PointF((V1.x + V2.x) / 2, (V1.y + V2.y) / 2);
                gr.DrawString(((Weight).ToString()+":"+(char)('a'+ numberE)).ToString(), fo, br, point);
 
                /*point = new PointF((V1.x + V2.x - 40) / 2, (V1.y + V2.y + 20) / 2);
                gr.DrawString(((Weight)).ToString(), fo, br, point);*/
 
                drawVertex(V1.x, V1.y, (E.v1 + 1).ToString());
                drawVertex(V2.x, V2.y, (E.v2 + 1).ToString());
            }
        }
 
        public void drawALLGraph(List<Vertex> V, List<Edge> E)
        {
            //Рисуем ребра
            for (int i = 0; i < E.Count; i++)
            {
                if (E[i].v1 == E[i].v2)
                {
                    gr.DrawArc(darkGoldPen, (V[E[i].v1].x - 2 * R), (V[E[i].v1].y - 2 * R), 2 * R, 2 * R, 90, 270);
                    point = new PointF(V[E[i].v1].x - (int)(2.75 * R), V[E[i].v1].y - (int)(2.75 * R));
                    gr.DrawString(((E[i].Weight.ToString())+":"+(char)('a' + i)).ToString(), fo, br, point);
                }
                else
                {
                    gr.DrawLine(darkGoldPen, V[E[i].v1].x, V[E[i].v1].y, V[E[i].v2].x, V[E[i].v2].y);
                    point = new PointF((V[E[i].v1].x + V[E[i].v2].x) / 2, (V[E[i].v1].y + V[E[i].v2].y) / 2);
                    gr.DrawString(((E[i].Weight.ToString()) + ":" + (char)('a' + i)).ToString(), fo, br, point);
                }
            }
            //Рисуем вершины
            for (int i = 0; i < V.Count; i++)
            {
                drawVertex(V[i].x, V[i].y, (i + 1).ToString());
            }
        }
}


Класс Form1.cs
Кликните здесь для просмотра всего текста
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
 
namespace MathGraph
{
    public partial class Form1 : Form
    {
        DrawGraph G;
        List<Vertex> V;
        List<Edge> E;
        int[,] AMatrix; //Матрица смежности
        int[,] IMatrix; //Матрица инцидентности
 
        int selected1; //Выбранные вершины, для соединения ребрами
        int selected2;
 
        private ReportForm reportForm = new ReportForm();
 
        public Form1()
        {
            InitializeComponent();
            V = new List<Vertex>();
            G = new DrawGraph(sheet.Width, sheet.Height);
            E = new List<Edge>();
            sheet.Image = G.GetBitmap();
 
            sheet.SizeMode = PictureBoxSizeMode.AutoSize;
            vertexText.Text = "";
        }
 
                //Список смежности
        private void createListAdj()
        {
            AMatrix = new int[V.Count, V.Count];
            G.fillAdjacencyMatrix(V.Count, E, AMatrix);
            reportForm.listBoxMatrix.Items.Clear();
 
            string sOut = V.Count + "";
            for (int i = 0; i < V.Count; i++)
                sOut += /*(i + 1) +*/ " ";
            reportForm.listBoxMatrix.Items.Add(sOut);
            for (int i = 0; i < V.Count; i++)
            {
 
                for (int j = 0; j <= i; j++)
                {
                    if (AMatrix[i, j] != 0)
                    {
                        sOut = "";
                        sOut += (j + 1) + " " + (i + 1) + " " + AMatrix[i, j];
                        reportForm.listBoxMatrix.Items.Add(sOut);
                    }
                }
            }
        }
        //Выбрать вершину
        private void selectToolStrip_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Выбор вершины";
            selectToolStrip.Enabled = false;
            drawVertexToolStrip.Enabled = true;
            weightOfEdge.Enabled = true;
            drawEdgeToolStrip.Enabled = true;
            deleteVertexToolStrip.Enabled = true;
            adjVertex.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
            weightOfEdge.Enabled = true;
 
            G.clearSheet();
            G.drawALLGraph(V, E);
            sheet.Image = G.GetBitmap();
            selected1 = -1;
        }
 
        //Добавить вершину
        private void drawVertexToolStrip_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Добавление вершины";
            drawVertexToolStrip.Enabled = false;
            selectToolStrip.Enabled = true;
            drawEdgeToolStrip.Enabled = true;
            weightOfEdge.Enabled = true;
            deleteVertexToolStrip.Enabled = true;
            adjVertex.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
            weightOfEdge.Enabled = true;
 
            G.clearSheet();
            G.drawALLGraph(V, E);
            sheet.Image = G.GetBitmap();
        }
 
        //Добавить ребро
        private void drawEdgeToolStrip_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Добавление ребра";
            drawEdgeToolStrip.Enabled = false;
            selectToolStrip.Enabled = true;
            weightOfEdge.Enabled = true;
            drawVertexToolStrip.Enabled = true;
            deleteVertexToolStrip.Enabled = true;
            adjVertex.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
            weightOfEdge.Enabled = true;
 
            G.clearSheet();
            G.drawALLGraph(V, E);
            sheet.Image = G.GetBitmap();
            selected1 = -1;
            selected2 = -1;
        }
 
        private void adjVertex_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Проверка смежности вершин";
            adjVertex.Enabled = false;
            weightOfEdge.Enabled = true;
            drawEdgeToolStrip.Enabled = true;
            selectToolStrip.Enabled = true;
            drawVertexToolStrip.Enabled = true;
            deleteVertexToolStrip.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
            weightOfEdge.Enabled = true;
 
            G.clearSheet();
            G.drawALLGraph(V, E);
            sheet.Image = G.GetBitmap();
            selected1 = -1;
            selected2 = -1;
        }
 
        private void weightOfEdge_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Проверка веса ребра";
            weightOfEdge.Enabled = false;
            adjVertex.Enabled = true;
            drawEdgeToolStrip.Enabled = true;
            selectToolStrip.Enabled = true;
            drawVertexToolStrip.Enabled = true;
            deleteVertexToolStrip.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
 
            G.clearSheet();
            G.drawALLGraph(V, E);
            sheet.Image = G.GetBitmap();
            selected1 = -1;
            selected2 = -1;
        }
 
        //Удалить вершину
        private void deleteVertexToolStrip_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Удаление";
            deleteVertexToolStrip.Enabled = false;
            selectToolStrip.Enabled = true;
            drawVertexToolStrip.Enabled = true;
            drawEdgeToolStrip.Enabled = true;
            adjVertex.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
            weightOfEdge.Enabled = true;
 
            G.clearSheet();
            G.drawALLGraph(V, E);
            sheet.Image = G.GetBitmap();
        }
 
        //Удалить граф
        private void deleteGraphToolStrip_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Удаление графа";
            selectToolStrip.Enabled = true;
            drawVertexToolStrip.Enabled = true;
            drawEdgeToolStrip.Enabled = true;
            weightOfEdge.Enabled = true;
            deleteVertexToolStrip.Enabled = true;
            adjVertex.Enabled = true;
            countVertex.Enabled = true;
            countEdge.Enabled = true;
            weightOfEdge.Enabled = true;
 
            const string message = "Вы действительно хотите удалить граф?";
            const string caption = "Удаление";
            var MBSave = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (MBSave == DialogResult.Yes)
            {
                V.Clear();
                E.Clear();
                G.clearSheet();
                sheet.Image = G.GetBitmap();
                vertexText.Text = "";
            }
        }
 
        private void sheet_MouseClick(object sender, MouseEventArgs e)
        {
            //Нажато меню "Выбрать", ищем степень вершины
            if (selectToolStrip.Enabled == false)
            {
                for (int i = 0; i < V.Count; i++)
                {
                    if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R)
                    {
                        if (selected1 != -1)
                        {
                            selected1 = -1;
                            G.clearSheet();
                            G.drawALLGraph(V, E);
                            sheet.Image = G.GetBitmap();
                        }
                        if (selected1 == -1)
                        {
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected1 = i;
                            sheet.Image = G.GetBitmap();
                            createAdjAndOutDeg();
                            int degree = 0;
                            for (int j = 0; j < V.Count; j++)
                                degree += AMatrix[selected1, j];
                            vertexText.Text = "Степень вершины №" + (selected1 + 1) + " равна " + degree;
                            break;
                        }
                    }
                }
            }
            //Нажато меню "Добавить вершину"
            if (drawVertexToolStrip.Enabled == false)
            {
                V.Add(new Vertex(e.X, e.Y));
                G.drawVertex(e.X, e.Y, V.Count.ToString());
                sheet.Image = G.GetBitmap();
            }
            //Нажато меню "Добавить ребро"
            if (drawEdgeToolStrip.Enabled == false)
            {
                for (int i = 0; i < V.Count; i++)
                {
                    if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R)
                    {
                        if (selected1 == -1)
                        {
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected1 = i;
                            sheet.Image = G.GetBitmap();
                            break;
                        }
                        if (selected2 == -1)
                        {
                            string Weigh = Interaction.InputBox("Введите вес ребра", "Добавление ребра", "1", -1, -1);
                            if (Weigh == "")
                            {
                                break;
                            }
                            int Weight = 0;
                            try
                            {
                                Weight = int.Parse(Weigh);
                                if (Weight <= 0)
                                {
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Введите число", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                break;
                            }
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected2 = i;
                            E.Add(new Edge(selected1, selected2, Weight));
 
                            G.drawEdge(V[selected1], V[selected2], E[E.Count - 1], E.Count - 1, Weight);
                            selected1 = -1;
                            selected2 = -1;
                            sheet.Image = G.GetBitmap();
                            break;
                        }
                    }
                }
            }
            //Проверить смежность вершин 
            if (adjVertex.Enabled == false)
            {
                for (int i = 0; i < V.Count; i++)
                {
                    if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R)
                    {
                        if (selected1 == -1)
                        {
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected1 = i;
                            sheet.Image = G.GetBitmap();
                            break;
                        }
                        if (selected2 == -1)
                        {
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected2 = i;
 
                            AMatrix = new int[V.Count, V.Count];
                            G.fillAdjacencyMatrix(V.Count, E, AMatrix);
 
                            if (AMatrix[selected1, selected2] > 0)
                            {
                                MessageBox.Show("Вершины смежны", "Смежность", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
                            else
                            {
                                MessageBox.Show("Вершины не смежны", "Смежность", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
 
                            selected1 = -1;
                            selected2 = -1;
                            sheet.Image = G.GetBitmap();
                            G.drawALLGraph(V, E);
                            break;
                        }
                    }
                }
            }
            //Узнать вес ребра 
            if (weightOfEdge.Enabled == false)
            {
                for (int i = 0; i < V.Count; i++)
                {
                    if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R)
                    {
                        if (selected1 == -1)
                        {
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected1 = i;
                            sheet.Image = G.GetBitmap();
                            break;
                        }
                        if (selected2 == -1)
                        {
                            G.drawSelectedVertex(V[i].x, V[i].y);
                            selected2 = i;
 
                            AMatrix = new int[V.Count, V.Count];
                            G.fillAdjacencyMatrix(V.Count, E, AMatrix);
 
                            MessageBox.Show("Вес ребра: " + AMatrix[selected1, selected2], "Вес ребра", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
 
 
                            selected1 = -1;
                            selected2 = -1;
                            sheet.Image = G.GetBitmap();
                            G.drawALLGraph(V, E);
                            break;
                        }
                    }
                }
            }
            //Нажато меню "Удалить вершину"
            if (deleteVertexToolStrip.Enabled == false)
            {
                bool flag = false; //Удалили ли что-нибудь по ЭТОМУ клику
                //Ищем, возможно была нажата вершина
                for (int i = 0; i < V.Count; i++)
                {
                    if (Math.Pow((V[i].x - e.X), 2) + Math.Pow((V[i].y - e.Y), 2) <= G.R * G.R)
                    {
                        for (int j = 0; j < E.Count; j++)
                        {
                            if ((E[j].v1 == i) || (E[j].v2 == i))
                            {
                                E.RemoveAt(j);
                                j--;
                            }
                            else
                            {
                                if (E[j].v1 > i) E[j].v1--;
                                if (E[j].v2 > i) E[j].v2--;
                            }
                        }
                        V.RemoveAt(i);
                        flag = true;
                        break;
                    }
                }
                //Ищем, возможно было нажато ребро
                if (!flag)
                {
                    for (int i = 0; i < E.Count; i++)
                    {
                        if (E[i].v1 == E[i].v2) //Если это петля
                        {
                            if ((Math.Pow((V[E[i].v1].x - G.R - e.X), 2) + Math.Pow((V[E[i].v1].y - G.R - e.Y), 2) <= ((G.R + 2) * (G.R + 2))) &&
                                (Math.Pow((V[E[i].v1].x - G.R - e.X), 2) + Math.Pow((V[E[i].v1].y - G.R - e.Y), 2) >= ((G.R - 2) * (G.R - 2))))
                            {
                                E.RemoveAt(i);
                                flag = true;
                                break;
                            }
                        }
                        else //Не петля
                        {
                            if (((e.X - V[E[i].v1].x) * (V[E[i].v2].y - V[E[i].v1].y) / (V[E[i].v2].x - V[E[i].v1].x) + V[E[i].v1].y) <= (e.Y + 4) &&
                                ((e.X - V[E[i].v1].x) * (V[E[i].v2].y - V[E[i].v1].y) / (V[E[i].v2].x - V[E[i].v1].x) + V[E[i].v1].y) >= (e.Y - 4))
                            {
                                if ((V[E[i].v1].x <= V[E[i].v2].x && V[E[i].v1].x <= e.X && e.X <= V[E[i].v2].x) ||
                                    (V[E[i].v1].x >= V[E[i].v2].x && V[E[i].v1].x >= e.X && e.X >= V[E[i].v2].x))
                                {
                                    E.RemoveAt(i);
                                    flag = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                //Если что-то было удалено, то обновляем граф на экране
                if (flag)
                {
                    G.clearSheet();
                    G.drawALLGraph(V, E);
                    sheet.Image = G.GetBitmap();
                }
            }
        }
 
      
                private void выходToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
 
       
        private void countEdge_Click(object sender, EventArgs e)
        {
            vertexText.Text = "Проверка количества рёбер";
            if (E.Count > 0)
            {
                IMatrix = new int[V.Count, E.Count];
                G.fillIncidenceMatrix(V.Count, E, IMatrix);
                MessageBox.Show("Количество рёбер графа: " + E.Count.ToString(), "Количество рёбер графа", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                MessageBox.Show("Количество рёбер графа: " + 0, "Количество рёбер графа", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
 
                        /**********Преобразование в матрицу смежности***********/
                for(int i=0; i<size; i++)
                {
                    for(int j=0; j<size; j++)
                    {
                        resultMatrix[i,j] = 0;
                    }
                }
                for(int i=1; i<counterRows; i++)
                {
                    int row = int.Parse(matrix[i][0]);
                    int col = int.Parse(matrix[i][1]);
 
                    resultMatrix[row-1,col-1] = int.Parse(matrix[i][2]);
                    resultMatrix[col-1,row-1] = int.Parse(matrix[i][2]);
                }
                /**********Конец преобразования в матрицу смежности***********/
                int x0 = 300;
                int y0 = 160;
 
                for (int i = 0; i < size; i++)
                {
                    int X = (int)(x0 + 120 * Math.Cos(2 * Math.PI * i / size));
                    int Y = (int)(y0 + 120 * Math.Sin(2 * Math.PI * i / size));
 
                    V.Add(new Vertex(X, Y));
                    G.drawVertex(X, Y, V.Count.ToString());
                    sheet.Image = G.GetBitmap();
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        if (i == j && resultMatrix[i,j] == 0)
                        {
                            continue;
                        }
                        else if (i > j || resultMatrix[i, j] == 0)
                        {
                            continue;
                        }
                        else
                        {
                            E.Add(new Edge(i, j, resultMatrix[i, j]));
                            G.drawEdge(V[i], V[j], E[E.Count - 1], E.Count - 1, resultMatrix[i, j]);
                        }
                    }
                }
                sheet.Image = G.GetBitmap();
            }
        }
 
        
 
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //Здесь решение
        }
    }
}
0
11.12.2018, 18:12
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
11.12.2018, 18:12
Помогаю со студенческими работами здесь

Покажите, что в любом графе количество вершин нечетной степени четно.
Покажите, что в любом графе количество вершин нечетной степени четно.

Раскрасить вершины графа, чтобы смежные вершины были окрашены в различные цвета
Добрый день. Прошу вашей помощи от безысходности. 4 дня назад выдана задача, которую требуется...

Проложить в графе путь из 1 вершины в 9, идя только по ребрам, сумма номеров вершин которых кратна трем
в стране &quot;цифра&quot; есть 9 городов с названиями 1,2,..,9. путешественник обнаружил , что два города...

Доказать,что в любом графе с n вершинами есть минимум две вершины с одинаковой степенью
Помогите пожалуйста доказать,что в любом графе с n вершинами есть минимум две вершины с одинаковой...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru