Advertisement
Pit_Anonim

M

Nov 25th, 2021
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int a, b;
  8.     std::cin>>a>>b;
  9.     int matrix[a][a];
  10.  
  11.     std::vector<std::pair<int, int>> pairs;
  12.  
  13.     int j,k;
  14.     for (int x = 0; x < b; x++) {
  15.         std::cin>>j>>k;
  16.         pairs.push_back(std::pair<int,int>(j-1,k-1));
  17.     }
  18.  
  19.     for (int x = 0; x < a; x++) {
  20.         for (int y = 0; y < a; y++) {
  21.             matrix[x][y] = 0;
  22.         }
  23.     }
  24.  
  25.     for (int x = 0; x < a; x++)
  26.         for (int y = 0; y < a; y++) {
  27.             for (int l = 0; l < pairs.size(); l++) {
  28.                 if (pairs[l].first == x && pairs[l].second == y) {
  29.                     matrix[x][y] = 1;
  30.                     matrix[y][x] = 1;
  31.                 }
  32.             }
  33.         }
  34.  
  35.     int g = 0;
  36.     for (int x = 0; x < a; x++) {
  37.         for (int y = 0; y < a; y++) {
  38.             if (matrix[x][y]) {
  39.               g++;
  40.             }
  41.         }
  42.         cout<<g<<endl;
  43.         g=0;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement