3
vector<vector<int>> pc, adj; // pc is the parent child edge in our dfs4
vector<vector<bool>> childs; // 2D array to store that i is a parent of j5
vector<int> child_xor, nums,6
par; // child_xor to store result of xors of a child node and par is a7
// gloable array to track the parents of a node in dfs13
for (int p : par) childs[p][i] = true; // Defining this node as the child of all its parents17
for (int child : adj[i])18
if (!visited[child]) {19
pc.push_back({i, child});20
ans ^= dfs(child); // Recurcively calculating xors25
return child_xor[i] = ans;29
int minimumScore(vector<int> &nums, vector<vector<int>> &edges) {30
// Initialising gloable variables31
int n = nums.size(), ans = INT_MAX;32
visited = vector<bool>(n);33
pc = vector<vector<int>>();34
adj = vector<vector<int>>(n);35
child_xor = vector<int>(n, 0);36
childs = vector<vector<bool>>(n, vector<bool>(n, false));40
// Creating an adjacency matrix41
for (vector<int> &edge : edges)42
adj[edge[0]].push_back(edge[1]), adj[edge[1]].push_back(edge[0]);46
for (int i = 0; i < pc.size(); i++)47
for (int j = i + 1; j < pc.size(); j++) { // removing an edge i and j48
int a = pc[i][1], b = pc[j][1]; // node that will come below when you49
// delete an edge i and j50
int xa = child_xor[a], xb = child_xor[b], xc = child_xor[0];57
ans = min(max(xa, max(xb, xc)) - min(xa, min(xb, xc)), ans);