-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph network.cpp
More file actions
36 lines (34 loc) · 891 Bytes
/
Copy pathGraph network.cpp
File metadata and controls
36 lines (34 loc) · 891 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
25
26
27
28
29
30
31
32
33
34
35
36
class Solution
{
public:
vector<int> adj[110];
int maximalNetworkRank(int n, vector<vector<int>> &roads)
{
map<int, int> network;
for (auto it : roads)
{
adj[it[0]].push_back(it[1]);
adj[it[1]].push_back(it[0]);
network[it[0]]++;
network[it[1]]++;
}
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
std::vector<int>::iterator it;
it = find(adj[i].begin(), adj[i].end(), j);
if (it != adj[i].end())
{
ans = max(ans, (network[i] + network[j] - 1));
}
else
{
ans = max(ans, (network[i] + network[j]));
}
}
}
return ans;
}
};