SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int countFriends(const vector < vector<bool> > &G) {
  8.     int friends = 0;
  9.     for (int x = 1; x < G.size(); x++) {
  10.         for (int y = 0; y < x; y++) {
  11.             if (G[x][y])
  12.                 friends++;
  13.         }
  14.     }
  15.    
  16.     return friends;
  17. }
  18.  
  19. bool friendInCommon( const vector < vector <bool> > &G, int i, int j) {
  20.     vector <int> friends_i,
  21.                  friends_j;
  22.     for (int x = 0; x < G.size(); x++) {
  23.         if (G[i][x])
  24.             friends_i.push_back(x);
  25.         if (G[j][x])
  26.             friends_j.push_back(x);
  27.     }
  28.     for (int x = 0; x < friends_j.size() && x < friends_j.size(); x++) {
  29.         if (friends_j[x] == friends_i[x])
  30.             return true;
  31.     }
  32.    
  33.     return false;
  34. }
  35.  
  36. int main() {
  37.  
  38.     int n, a;
  39.     cin >> n;
  40.     vector< vector<bool> > V ( n, std::vector<bool>(n));
  41.     for (int i = 0; i < n; i++) {
  42.         for (int j = 0; j < n; j++) {
  43.             cin >> a;
  44.             V[i][j] = (a != 0);
  45.         }
  46.     }
  47.  
  48.     cout << countFriends(V) << '\n';
  49.  
  50.     cout << ( friendInCommon(V,0,1) ? "True" : "False") << '\n';
  51.     cout << ( friendInCommon(V,2,4) ? "True" : "False") << '\n';
  52.     cout << ( friendInCommon(V,3,0) ? "True" : "False") << '\n';
  53.  
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top