This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=1000+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
vector<ll> e[N];
ll adj[N][N];
vector<pair<ll,ll> > v[N];
ll vis[N];
ll n , m , q;
void dfs(ll x, ll w)
{
    if(vis[x]) return;
    vis[x] = 1;
    for(int i = 0; i < v[x].sz; i++)
    {
        ll to = v[x][i].F , curw = v[x][i].S;
        if(curw>=w) dfs(to,w);
    }
}
void solve()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        ll x, y, w; cin >> x >> y >> w;
        e[i] = {x,y,w};
        v[x].push_back({y,w});
        v[y].push_back({x,w});
    }
    cin >> q;
    while(q--)
    {
        ll tp; cin >> tp;
        if(tp==1)
        {
            ll j , w; cin >> j >> w; j--;
            ll x = e[j][0] , y = e[j][1], curw = e[j][2];
            e[j][2] = w;
            ll lst = -1;
            for(int i = 1; i < v[x].sz; i++)
            {
                if(v[x][i-1].F==y&&curw==v[x][i-1].S&&lst==-1) lst = i-1;
                if(lst!=-1) swap(v[x][i],v[x][i-1]);
            }
            lst = -1;
            for(int i = 1; i < v[y].sz; i++)
            {
                if(v[y][i-1].F==x&&curw==v[y][i-1].S&&lst==-1) lst = i-1;
                if(lst!=-1) swap(v[y][i],v[y][i-1]);
            }
            v[x].back().S = w;
            v[y].back().S = w;
        }
        else
        {
            ll s, w; cin >> s >> w;
            //for(int i = 1; i <= n; i++) {for(int j = 0; j < v[i].sz; j++) cout << v[i][j].F << v[i][j].S << " "; cout << endl;}
            for(int i = 1; i <= n; i++) vis[i] = 0;
            dfs(s,w);
            ll cnt = 0;
            for(int i = 1; i <= n ;i++) if(vis[i]) cnt++;
            cout << cnt << endl;
        }
    }
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    while(TT--)
        solve();
    return 0;
}
Compilation message (stderr)
bridges.cpp: In function 'void dfs(ll, ll)':
bridges.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i = 0; i < v[x].sz; i++)
      |                      ^
bridges.cpp: In function 'void solve()':
bridges.cpp:67:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for(int i = 1; i < v[x].sz; i++)
      |                              ^
bridges.cpp:73:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             for(int i = 1; i < v[y].sz; i++)
      |                              ^| # | 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... |