leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1615.cpp (556B)


      1 class Solution {
      2   public:
      3     int maximalNetworkRank(int n, vector<vector<int>> &roads) {
      4         int mat[101][101] = {0}, degree[101] = {0};
      5         int res = 0;
      6 
      7         for (int i = 0; i < roads.size(); i++) {
      8             int u = roads[i][0], v = roads[i][1];
      9             degree[u]++, degree[v]++;
     10             mat[u][v] = mat[v][u] = 1;
     11         }
     12 
     13         for (int i = 0; i < n; i++) {
     14             for (int j = i + 1; j < n; j++) {
     15                 res = max(res, degree[i] + degree[j] - mat[i][j]);
     16             }
     17         }
     18         return res;
     19     }
     20 };