VictoriaLodochkina

sacod lab 2_6

Mar 1st, 2021
354
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int N = 6;
  5. int m[N][N];
  6. char used[N]{};
  7.  
  8. void fill_the_matrix() {
  9.     for (int i = 0; i < N; i++)
  10.         for (int j = 0; j < N; j++)
  11.             cin >> m[i][j];
  12. }
  13.  
  14. void dfs(int s) {
  15.     used[s] = 1;
  16.     for (int i = 0; i < N; i++) {
  17.         if (used[i] == 0 && m[s][i] == 1)
  18.             dfs(i);
  19.     }
  20. }
  21.  
  22. void dfs2(int s) {
  23.     used[s] = 1;
  24.     for (int i = 0; i < N; i++) {
  25.         if (used[i] == 0 && (m[s][i] == 1 || m[i][s] == 1))
  26.             dfs2(i);
  27.     }
  28. }
  29.  
  30. int sum_edges() {
  31.     int sum = 0;
  32.     for (int i = 0; i < N; i++)
  33.         for (int j = 0; j < N; j++)
  34.             sum += abs(m[i][j]);
  35.     return sum;
  36. }
  37.  
  38. int main()
  39. {
  40.     cout << " Enter matrix ";
  41.     int cnt = 0;
  42.     int edges = 0;
  43.     int highs = N;
  44.     fill_the_matrix();
  45.     edges = sum_edges();
  46.     //dfs(3);
  47.     char ch;
  48.     cout << "Which type of graph have you written ? (a - non orient / b - orient)\n";
  49.     cin >> ch;
  50.     for (int i = 0; i < N; i++) {
  51.         if (used[i] == 0) {
  52.             if (ch == 'a') {
  53.                 dfs(i);
  54.             }
  55.             else {
  56.                 dfs2(i);
  57.             }
  58.             cnt++;
  59.         }
  60.     }
  61.     if (ch == 'a') {
  62.         edges /= 2;
  63.     }
  64.  
  65.     cout << "KCC: " << cnt << endl;
  66.     cout << "Edges: " << edges << endl;
  67.     cout << "Higs: " << highs << endl;
  68.     int l = edges - highs + cnt;
  69.     cout << "Your result: " << l;
  70.  
  71.     return 0;
  72. }
  73.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×