Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rishabhgargg/6b7b4e71c78beb1bf20851fe58c522eb to your computer and use it in GitHub Desktop.
Save rishabhgargg/6b7b4e71c78beb1bf20851fe58c522eb to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
// Initialize familiarity matrix, true means they are familiar
vector<vector<bool>> familiar(n + 1, vector<bool>(n + 1, true));
// Mark the pairs who are not familiar with each other
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
familiar[x][y] = false;
familiar[y][x] = false;
}
int efficient_count = 0;
// Check all possible segments [a, b]
for (int a = 1; a <= n; ++a) {
for (int b = a; b <= n; ++b) {
bool is_efficient = true;
for (int i = a; i <= b && is_efficient; ++i) {
for (int j = i + 1; j <= b && is_efficient; ++j) {
if (!familiar[i][j]) {
is_efficient = false;
}
}
}
if (is_efficient) {
++efficient_count;
}
}
}
cout << efficient_count << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment