#include <bits/stdc++.h>
using namespace std;
int parent[50000], sizes[50000];
vector<pair<int &, int>> history;
int trueparent(int n){
    if (parent[n] == n) return n;
    else return (trueparent(parent[n]));
}
void unite (int x, int y){
    int a = trueparent(x), b = trueparent(y);
    if (a == b) return;
    if (sizes[a] > sizes[b]){
    }
    else{
        swap(a, b);
    }
    history.push_back({sizes[a], sizes[a]});
    history.push_back({parent[b], parent[b]});
    parent[b] = a;
    sizes[a] += sizes[b];
}
bool greaterse(pair<pair<int, int>, pair<int, int>> x, pair<pair<int, int>, pair<int, int>> y){
    return x.first.first > y.first.first;
}
bool gretersee(pair<pair<int, int>, pair<int, int>> x, pair<pair<int, int>, pair<int, int>> y){
    return x.first.first < y.first.first;
}
bool gretersew(pair<pair<int, int>, pair<int, int>> x, pair<pair<int, int>, pair<int, int>> y){
    return x.first.second < y.first.second;
}
int main(){
    int n, m;
    cin >> n >> m;
    vector <pair<int, int>> adj[n];
    vector <pair<pair<int, int>, pair<int, int>>> roads;
    for (int i = 0; i < m; i++){
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        adj[x].push_back({y, z});
        adj[y].push_back({x, z});
        roads.push_back({{z, i}, {x, y}});
    } 
    int q;
    cin >> q;
    int k = sqrt(q);
    for (int i = 0; i < q; i += k){
        for (int i = 0; i < n; i++){
            sizes[i] = 1;
            parent[i] = i;
        }
        int start = i, e = min(q - 1, i + k - 1);
        vector <pair<pair<int, int>, pair<int, int>>> quirky;
        vector <pair<pair<int, int>,pair<int , int>>> calculations;
        for (int j = start; j <= e; j++){
            int x, y, z;
            cin >> x >> y >> z;
            y--;
            if (x == 2){
                calculations.push_back({{z, j}, {y, calculations.size()}});
            }
            else{
                quirky.push_back({{-1, roads[y].first.first}, {roads[y].second.first, roads[y].second.second}});
                quirky.push_back({{j, z}, {roads[y].second.first, roads[y].second.second}});
                roads[y].first.first = 0;
            }
        }
        sort(roads.begin(), roads.end(), greaterse);
        sort (calculations.begin(), calculations.end(), greaterse);
        sort (quirky.begin(), quirky.end(), gretersee);
        vector <int> ans (calculations.size());
        int prew = 0;
        for (auto f : calculations){
            int amo = 0;
            int cur = f.first.first;
            int s = f.first.second;
            while (prew != roads.size() && roads[prew].first.first >= cur){
            
                unite(roads[prew].second.first, roads[prew].second.second);
                prew++;
            }
            vector <pair<int, pair<int, int>>> badroads;
            history.clear();
            map <pair<int, int>, int> m;
            for (auto u : quirky){
                if (u.first.first > s) break;
                m[{u.second.first, u.second.second}] = u.first.second;
            }
            
            for (auto u : m){
                if (u.second >= cur){
                    
                    unite(u.first.first, u.first.second);
                }
            }
            ans[f.second.second] = sizes[trueparent(f.second.first)];
            while (history.size() != 0){
                history.back().first = history.back().second;
                history.pop_back();
            }
            
        }
        for (auto u : ans) cout << u <<endl;
        vector <pair<int, pair<int, int>>> badroads;
        int s = INT_MAX;
        map <pair<int, int>, int> m;
        for (auto u : quirky){
                if (u.first.first > s) break;
                m[{u.second.first, u.second.second}] = u.first.second;
            }
        for (auto &v : roads){
            if (v.first.first != 0) continue;
            v.first.first = m[{v.second.first, v.second.second}];
        }
        sort(roads.begin(), roads.end(), gretersew);
    }
}
    
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |