Advertisement
Guest User

lab4

a guest
Dec 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lab4_Graph
  8. {
  9.     class Program
  10.     {
  11.         static int[,] graph = new int[12, 14] {
  12.          /*0*/  {1,1,0,0,0,0,0,0,0,0,0,0,0,0},
  13.                 {1,0,0,0,0,0,0,0,0,0,0,0,0,0},
  14.                 {0,0,1,1,1,0,0,0,0,0,0,0,0,0},
  15.                 {0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  16.                 {0,0,0,0,0,1,1,0,0,0,0,0,0,0},
  17.                 {0,1,0,1,0,0,0,1,1,0,0,0,0,0},
  18.                 {0,0,0,0,0,0,0,1,0,1,1,0,0,0},
  19.                 {0,0,0,0,1,0,0,0,0,0,0,1,0,0},
  20.                 {0,0,0,0,0,1,0,0,0,0,0,0,1,0},
  21.                 {0,0,0,0,0,0,1,0,0,1,0,0,1,0},
  22.                 {0,0,0,0,0,0,0,0,1,0,0,0,0,1},
  23.                 {0,0,0,0,0,0,0,0,0,0,1,1,0,1 }
  24.             };
  25.  
  26.         const int n = 12;
  27.         const int m = 14;
  28.  
  29.         static bool[] used = new bool[n];
  30.         static int j = 0;
  31.         static int r = 0;
  32.         static int i = 0;
  33.         static int k = 0;
  34.  
  35.         static void Main(string[] args)
  36.         {
  37.             dfs(1);
  38.  
  39.  
  40.             Console.ReadKey();
  41.         }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.        
  48.  
  49.         static void dfs(int t)
  50.         {
  51.             used[t] = true;
  52.             int p;
  53.             for (i = k; i < n; i++)
  54.             {
  55.                 j = r;
  56.                 if ((graph[i, j] != 0) && (!used[i]))
  57.                 {
  58.                     used[i] = true;
  59.                     p = i;
  60.                     Console.Out.WriteLine(i);
  61.                     for (j = 0; j < m; j++)
  62.                     {
  63.                         i = p;
  64.                         if (graph[i, j] != 0)
  65.                         {
  66.                             r = j;
  67.                             for (k = 0; k < n; k++)
  68.                             {
  69.                                 j = r;
  70.                                 if ((graph[k, j] != 0) && (!used[k]))
  71.                                 {
  72.                                     dfs(i);
  73.                                 }
  74.                             }
  75.                         }
  76.                     }
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }
  82.     //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement