3
vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>> &edges) {4
// INT_MAX/2-1 used to avoid overflow5
vector<vector<int>> graph(n, vector<int>(n, INT_MAX / 2 - 1));7
int u = e[0] - 1, v = e[1] - 1;8
graph[u][v] = graph[v][u] = 1;11
// floyed-warshall algorithm12
for (int k = 0; k < n; k++) {13
for (int i = 0; i < n; i++) {14
for (int j = 0; j < n; j++) {15
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);20
vector<int> res(n - 1, 0);22
/* Check for each combination of nodes and see if it's a subtree or not.23
If it's a subtree then see maximum distance that can be reached.*/27
for (int sub = 0; sub < (1 << n); sub++) {28
// Number of nodes = nodes29
int nodes = __builtin_popcount(sub);34
for (int i = 0; i < n; i++)36
for (int j = i + 1; j < n; j++)38
// if i to j edge increment e39
edges += graph[i][j] == 1;41
dist = max(dist, graph[i][j]);44
// chech its a subtree and distance > 0 if it's then its a subtree having46
if (edges == nodes - 1 && dist > 0) {