-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1615.cpp
More file actions
24 lines (24 loc) · 766 Bytes
/
1615.cpp
File metadata and controls
24 lines (24 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
int maximalNetworkRank(int n, vector<vector<int>>& roads) {
vector<int> degrees(n, 0);
unordered_map<int, unordered_set<int>> mp;
for (auto& road : roads) {
degrees[road[0]]++;
degrees[road[1]]++;
mp[road[0]].insert(road[1]);
mp[road[1]].insert(road[0]);
}
int maxValue = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int indegreeI = degrees[i];
int indegreeJ = degrees[j];
int total = indegreeI + indegreeJ;
if (mp[i].count(j)) total--;
maxValue = max(maxValue, total);
}
}
return maxValue;
}
};