1583. 统计不开心的朋友
不开心的朋友算我一个
按题意做就好了
class Solution {
public:
int unhappyFriends(int n, vector<vector<int>>& preferences, vector<vector<int>>& pairs) {
vector<vector<int>>f(n + 1, vector<int>(n + 1, 0));
for(auto& e : pairs){
int a = e[0], b = e[1], i = 0, j = 0; f[a][b] = f[b][a] = 1;
while(i < preferences[a].size() && preferences[a][i] != b)f[a][preferences[a][i++]] = 2;
while(j < preferences[b].size() && preferences[b][j] != a)f[b][preferences[b][j++]] = 2;
}
int ans = 0;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(f[i][j] == 2 && f[j][i] == 2){
ans += 1;
break;
}
return ans;
}
};