text: Output For each guess print the minimum possible hardness of the division in described scenario.Example Input 5 6 5 5 4 86 5 1 0 1 3 38 2 1 33 2 4 28 2 3 40 3 5 2 6 1 3 2 3 1 6 Output -1 33 -1 -1 33 # Solution #include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 1000, M = N * (N - 1) / 2; int dsu[N * 2]; int find(int i) { return dsu[i] < 0 ?i : (dsu[i] = find(dsu[i])); } bool join(int i, int j) { i = find(i); j = find(j); if (i == j) return false; if (dsu[i] > dsu[j]) dsu[i] = j; else { if (dsu[i] == dsu[j]) dsu[i]--; dsu[j] = i; } return true; } int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); static int ii[M], jj[M], ww[M], hh[M]; for (int h = 0; h < m; h++) { int i, j, w; scanf("%d%d%d", &i, &j, &w), i--, j--; ii[h] = i; jj[h] = j; ww[h] = w; hh[h] = h; } sort(hh, hh + m, [](int a, int b) { return ww[a] > ww[b]; }); while (q-- > 0) { int l, r; scanf("%d%d", &l, &r), l--, r--; fill_n(dsu, n * 2, -1); int w = -1; for (int h = 0; h < m; h++) { int h_ = hh[h]; if (l <= h_ && h_ <= r) { int i = ii[h_]; int j = jj[h_]; int i0 = i << 1, i1 = i0 | 1; int j0 = j << 1, j1 = j0 | 1; if (join(i0, j1) && !join(i1, j0)) { w = ww[h_]; break; } } } printf("%d\n", w); } }