fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace Кол_во_циклов_в_графе_1_
  9. {
  10. class Program
  11. {
  12. public static int vertex_count = 16;
  13. public static int edge_count = 16;
  14. public static int[,] Graph;
  15. public static int[] cnt;
  16.  
  17. static void Main(string[] args)
  18. {
  19. Graph = new int[vertex_count, edge_count];
  20.  
  21. Graph[0, 1] = 1;
  22. Graph[0, 2] = 1;
  23. Graph[0, 3] = 1;
  24. Graph[3, 4] = 1;
  25. Graph[3, 5] = 1;
  26. Graph[4, 6] = 1;
  27. Graph[4, 8] = 1;
  28. Graph[5, 14] = 1;
  29. Graph[5, 15] = 1;
  30. Graph[5, 6] = 1;
  31. Graph[6, 10] = 1;
  32. Graph[8, 9] = 1;
  33. Graph[10, 12] = 1;
  34. Graph[12, 11] = 1;
  35. Graph[12, 13] = 1;
  36. Graph[13, 14] = 1;
  37.  
  38. for (int i = 0; i < vertex_count; i++) {
  39. for (int j = 0; j < edge_count; j++) {
  40. if (Graph[i, j] == 1)
  41. Graph[j, i] = 1;
  42.  
  43. Console.Write(Graph[i, j] + " ");
  44. }
  45. Console.WriteLine();
  46. }
  47. Console.WriteLine();
  48.  
  49. cnt = new int[vertex_count];
  50.  
  51. for (int i = 0; i < vertex_count; i++) {
  52. bool[] Use = new bool[vertex_count];
  53. for(int j = 0; j < edge_count; j++) {
  54. Use[j] = false;
  55. }
  56. Use[i] = true;
  57. DFS(Use, i, i, 0);
  58. }
  59.  
  60. int y = 0;
  61. string s;
  62. for (int i = 2; i < vertex_count; i++) {
  63. y = cnt[i]/(i*2);
  64. s = "cnt[" + Convert.ToString(i) + "]: " + Convert.ToString(y);
  65. Console.WriteLine(s);
  66. }
  67. Console.ReadKey();
  68. }
  69. public static void DFS (bool []use, int k, int anc, int wave)
  70. {
  71. if (Graph[k, anc] != 0) cnt[wave+1]++;
  72. use[k] = true;
  73. for(int i = 0; i < vertex_count; i++)
  74. {
  75. if (!use[i] && Graph[k,i] != 0)
  76. {
  77. use[i] = true;
  78. DFS(use, i, anc, wave + 1);
  79. use[i] = false;
  80. }
  81. }
  82. }
  83. }
  84. }
  85.  
Success #stdin #stdout 0.03s 24152KB
stdin
Standard input is empty
stdout
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 
0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 
0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 
0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 
0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 

cnt[2]: 8
cnt[3]: 0
cnt[4]: 1
cnt[5]: 0
cnt[6]: 1
cnt[7]: 0
cnt[8]: 1
cnt[9]: 0
cnt[10]: 0
cnt[11]: 0
cnt[12]: 0
cnt[13]: 0
cnt[14]: 0
cnt[15]: 0