2
public int maximalNetworkRank(int n, int[][] roads) {4
// number of road connected to city5
int[] numRoadsConnectedCity = new int[100 + 1];7
// road exist between two two cities8
boolean[][] raadExist = new boolean[n][n];10
for (int[] cities : roads) {12
// increment the count of numbers of connected city13
numRoadsConnectedCity[cities[0]]++;14
numRoadsConnectedCity[cities[1]]++;16
// mark road exist, between two cities17
raadExist[cities[0]][cities[1]] = true;18
raadExist[cities[1]][cities[0]] = true;22
for (int city1 = 0; city1 < n - 1; city1++) {23
for (int city2 = city1 + 1; city2 < n; city2++) {25
// count total number of road connected to both city26
int rank = numRoadsConnectedCity[city1] + numRoadsConnectedCity[city2];28
// just decrement the rank, if both city connected29
if (raadExist[city1][city2]) rank--;31
maxRank = Math.max(maxRank, rank);