Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- using namespace std;
- int countFriends(const vector < vector<bool> > &G) {
- int friends = 0;
- for (int x = 1; x < G.size(); x++) {
- for (int y = 0; y < x; y++) {
- if (G[x][y])
- friends++;
- }
- }
- return friends;
- }
- bool friendInCommon( const vector < vector <bool> > &G, int i, int j) {
- vector <int> friends_i,
- friends_j;
- for (int x = 0; x < G.size(); x++) {
- if (G[i][x])
- friends_i.push_back(x);
- if (G[j][x])
- friends_j.push_back(x);
- }
- for (int x = 0; x < friends_j.size() && x < friends_j.size(); x++) {
- if (friends_j[x] == friends_i[x])
- return true;
- }
- return false;
- }
- int main() {
- int n, a;
- cin >> n;
- vector< vector<bool> > V ( n, std::vector<bool>(n));
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cin >> a;
- V[i][j] = (a != 0);
- }
- }
- cout << countFriends(V) << '\n';
- cout << ( friendInCommon(V,0,1) ? "True" : "False") << '\n';
- cout << ( friendInCommon(V,2,4) ? "True" : "False") << '\n';
- cout << ( friendInCommon(V,3,0) ? "True" : "False") << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement