- Blogathon, Blogathon-2021, disjoint-set, Graph, Mathematical, union-find

Maximum element in connected component of given node for Q queries

  #include using namespace std;  int Find(vector& parent, int a){    return parent[a] = (parent[a] == a)                           ? a                           : (Find(parent, parent[a]));}  void Union(vector& parent,           vector& rank,           vector& maxValue,           int a, int b){      a = Find(parent, a);    b = Find(parent, b);      if (a == b)        return;          if (rank[a] == rank[b]) {        rank[a]++;    }      if (rank[a] < rank[b]) {        int temp = a;        a = b;        b = temp;    }      parent[b] = a;          maxValue[a] = max(maxValue[a],                      maxValue[b]);}  void findMaxValueOfSet(    vector& arr,    vector& queries, int R, int N,    int M){              vector parent(R + 1);          vector rank(R + 1, 0);          vector maxValue(R + 1);      for (int i = 1; i < R + 1; i++) {                          parent[i] = maxValue[i] = i;    }      for (int i = 0; i < N; i++) {                                  Union(parent, rank, maxValue,              arr[i].first,              arr[i].second);    }      for (int i = 0; i < M; i++) {                          int P = Find(parent, queries[i]);                                  cout