Advertisement
Josif_tepe

Untitled

Mar 18th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, m;
  9.     cin >> n >> m;
  10.     bool ozboruvanje[n][n];
  11.     for(int i = 0; i < n; i++) {
  12.         for(int j = 0; j < n; j++) {
  13.             ozboruvanje[i][j] = false;
  14.         }
  15.     }
  16.     for(int i = 0; i < n; i++) {
  17.         ozboruvanje[i][i] = true;
  18.     }
  19.     int niza1[m + 1], niza2[m + 1];
  20.     for(int i = 0; i < m; i++) {
  21.         cin >> niza1[i] >> niza2[i];
  22.         niza1[i] -= 1;
  23.         niza2[i] -= 1;
  24.     }
  25.    
  26.     for(int i = 0; i < m; i++) {
  27.         int a = niza1[i];
  28.         int b = niza2[i];
  29.         for(int j = 0; j < n; j++) {
  30.             if(ozboruvanje[j][a] or ozboruvanje[j][b]) {
  31.                 ozboruvanje[j][a] = true;
  32.                 ozboruvanje[j][b] = true;
  33.             }
  34.         }
  35.     }
  36.     int maks = 0;
  37.     for(int i = 0; i < n; i++) {
  38.         int vkupno = 0;
  39.         for(int j = 0; j < n; j++) {
  40.             if(ozboruvanje[j][i]) {
  41.                 vkupno += 1;
  42.             }
  43.         }
  44.         if(maks < vkupno) {
  45.             maks = vkupno;
  46.         }
  47.     }
  48.     cout << maks - 1 << endl;
  49.     return 0;
  50. }
  51. /*
  52.  
  53.  1 2 3 4 5
  54.  
  55.  x = 4
  56.  
  57.  */
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement