//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("popcnt,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
 
#define fwd(i, a, n) for (int i = (a); i < (n); i ++)
#define rep(i, n) fwd(i, 0, n)
#define all(X) begin(X), end(X)
#define sz(X) ((int)X.size())
#define st first
#define nd second
#define pii pair<int, int>
#define vi vector<int>
#define ll long long
 
#ifdef LOC
auto &operator<<(auto &out, pair<auto, auto> a) {
	return out << "(" << a.st << ", " << a.nd << ")";
}
 
auto &operator<<(auto &out, auto a) {
	out << "{";
	for (auto b : a)
		out << b << ", ";
	return out << "}";
}
 
void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; }
#define debug(x...) cerr << __LINE__ << ": [" #x "]: ", dump(x)
#else
#define debug(...) 0
#endif
const int K = 1500;
vector<set<pair<int, long long>>> g;
vector<set<pair<int, long long>>> compG;
vector<vector<pair<long long, pii>>> events;
vector<int> color;
vector<int> myTime;
vector<bool> vis;
vector<bool> marked;
queue<pair<int, ll>> que;
queue<tuple<int, int, int, ll>> que1;
pair<int, long long> compresss(int v){
    vis[v] = true;
    vector<pair<int, ll>> t;
    for(auto p : g[v]){
        int u = p.st; ll d= p.nd;
        if(!vis[u]){
            pair<int, ll> q = compresss(u);
            if(q.st != -1){
                t.push_back({q.st, q.nd + d});
            }
        }
    }
    if(sz(t) > 1){
        marked[v] = true;
    }
    if(marked[v]){
        for(auto p : t){
            compG[p.st].insert({v, p.nd});
            compG[v].insert({p.st, p.nd});
        }
        return {v, 0};
    }else{
        if(sz(t) == 1){
            return t[0];
        }else{
            return {-1, -1};
        }
    }
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, q; cin>>n>>m>>q;
    g.resize(n+1);
    compG.resize(n+1);
    events.resize(n+1);
    color.resize(n+1, 0);
    myTime.resize(n+1, -1);
    vis.resize(n+1, false);
    marked.resize(n+1, false);
    rep(i, m){
        int a, b, d;
        cin>>a>>b>>d;
        g[a].insert({b, d});
        g[b].insert({a, d});
    }
    //debug(g);
    vector<array<ll, 4>> query(q);
    rep(i, q){
        cin>>query[i][0];
        if(query[i][0] == 1){
            cin>>query[i][1]>>query[i][2]>>query[i][3];
        }
        if(query[i][0] == 2){
            cin>>query[i][1]>>query[i][2];
        }
        if(query[i][0] == 3){
            cin>>query[i][1]>>query[i][2]>>query[i][3];
        }
        if(query[i][0] == 4){
            cin>>query[i][1];
        }
    }
    for(int t = 0; t < q; t += K){
        for(int i = 1; i <= n; i++)marked[i] = false;
        for(int i = 1; i <= n; i++)vis[i] = false;
        for(int j = t; j < q && j < t + K; j++){
            if(query[j][0] == 1 || query[j][0] == 2){
                marked[query[j][1]] = true;
                marked[query[j][2]] = true;
            }else{
                marked[query[j][1]] = true;
            }   
        }
        for(int i = 1; i <= n; i++){
            if(marked[i] && !vis[i])compresss(i);
        }
        for(int j = t; j < q && j < t + K; j++){
            if(query[j][0] == 1){
                int a = query[j][1]; int b =query[j][2]; long long d = query[j][3];
                g[a].insert({b, d});
                g[b].insert({a, d});
                compG[a].insert({b, d});
                compG[b].insert({a, d});
            }
            if(query[j][0] == 2){
                int  a = query[j][1]; int b = query[j][2];
                g[a].erase(g[a].lower_bound({b, 0}));
                g[b].erase(g[b].lower_bound({a, 0}));
                compG[a].erase(compG[a].lower_bound({b, 0}));
                compG[b].erase(compG[b].lower_bound({a, 0}));
            }
            if(query[j][0] == 3){
                que.push({query[j][1], query[j][2]});
                while(!que.empty()){
                    int v = que.front().st; ll d = que.front().nd; que.pop();
                    color[v] = query[j][3];
                    myTime[v] = j;
                    while(!events[v].empty() && events[v].back().st <= d)events[v].pop_back();
                    events[v].push_back({d, {j, query[j][3]}});
                    for(auto p : compG[v]){
                        if(myTime[p.st] != j && d - p.nd >= 0){
                            que.push({p.st, d - p.nd});
                        }
                    }
                }
                //colorDFS(query[j][1], -1, query[j][2], j, query[j][3]);
            }
            if(query[j][0] == 4){
                int u = query[j][1];
                cout<<color[u]<<"\n";
            }
        }
        for(int v = 1; v <= n; v++){
            if(marked[v] && sz(events[v]) > 0){
                for(auto p : g[v]){
                    if(!marked[p.st]){
                        que1.push({p.st, v, sz(events[v]) - 1, p.nd});
                        while(!que1.empty()){
                            int u = get<0>(que1.front()); 
                            int prev = get<1>(que1.front());
                            int ind = get<2>(que1.front());
                            ll d = get<3>(que1.front());
                            que1.pop();
                            while(ind >= 0 && events[v][ind].st < d)ind--;
                            if(ind < 0)continue;
                            if(events[v][ind].nd.st > myTime[u]){
                                myTime[u] = events[v][ind].nd.st;
                                color[u] = events[v][ind].nd.nd;
                            }
                            for(auto p : g[u]){
                                if(p.st != prev && !marked[p.st]){
                                    que1.push({p.st, u, ind, d + p.nd});
                                }
                            }
                        }
                        //updateColor(p.st, v, p.nd, events[v], sz(events[v]) - 1);
                    }
                }
            }
        }
        for(int v = 1; v <= n; v++){
            compG[v].clear();
            events[v].clear();
        }
    }
	return 0;
}
        1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194  | //#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("popcnt,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i ++) #define rep(i, n) fwd(i, 0, n) #define all(X) begin(X), end(X) #define sz(X) ((int)X.size()) #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #define ll long long #ifdef LOC auto &operator<<(auto &out, pair<auto, auto> a) { return out << "(" << a.st << ", " << a.nd << ")"; } auto &operator<<(auto &out, auto a) { out << "{"; for (auto b : a) out << b << ", "; return out << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << __LINE__ << ": [" #x "]: ", dump(x) #else #define debug(...) 0 #endif const int K = 1500; vector<set<pair<int, long long>>> g; vector<set<pair<int, long long>>> compG; vector<vector<pair<long long, pii>>> events; vector<int> color; vector<int> myTime; vector<bool> vis; vector<bool> marked; queue<pair<int, ll>> que; queue<tuple<int, int, int, ll>> que1; pair<int, long long> compresss(int v){ vis[v] = true; vector<pair<int, ll>> t; for(auto p : g[v]){ int u = p.st; ll d= p.nd; if(!vis[u]){ pair<int, ll> q = compresss(u); if(q.st != -1){ t.push_back({q.st, q.nd + d}); } } } if(sz(t) > 1){ marked[v] = true; } if(marked[v]){ for(auto p : t){ compG[p.st].insert({v, p.nd}); compG[v].insert({p.st, p.nd}); } return {v, 0}; }else{ if(sz(t) == 1){ return t[0]; }else{ return {-1, -1}; } } } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, q; cin>>n>>m>>q; g.resize(n+1); compG.resize(n+1); events.resize(n+1); color.resize(n+1, 0); myTime.resize(n+1, -1); vis.resize(n+1, false); marked.resize(n+1, false); rep(i, m){ int a, b, d; cin>>a>>b>>d; g[a].insert({b, d}); g[b].insert({a, d}); } //debug(g); vector<array<ll, 4>> query(q); rep(i, q){ cin>>query[i][0]; if(query[i][0] == 1){ cin>>query[i][1]>>query[i][2]>>query[i][3]; } if(query[i][0] == 2){ cin>>query[i][1]>>query[i][2]; } if(query[i][0] == 3){ cin>>query[i][1]>>query[i][2]>>query[i][3]; } if(query[i][0] == 4){ cin>>query[i][1]; } } for(int t = 0; t < q; t += K){ for(int i = 1; i <= n; i++)marked[i] = false; for(int i = 1; i <= n; i++)vis[i] = false; for(int j = t; j < q && j < t + K; j++){ if(query[j][0] == 1 || query[j][0] == 2){ marked[query[j][1]] = true; marked[query[j][2]] = true; }else{ marked[query[j][1]] = true; } } for(int i = 1; i <= n; i++){ if(marked[i] && !vis[i])compresss(i); } for(int j = t; j < q && j < t + K; j++){ if(query[j][0] == 1){ int a = query[j][1]; int b =query[j][2]; long long d = query[j][3]; g[a].insert({b, d}); g[b].insert({a, d}); compG[a].insert({b, d}); compG[b].insert({a, d}); } if(query[j][0] == 2){ int a = query[j][1]; int b = query[j][2]; g[a].erase(g[a].lower_bound({b, 0})); g[b].erase(g[b].lower_bound({a, 0})); compG[a].erase(compG[a].lower_bound({b, 0})); compG[b].erase(compG[b].lower_bound({a, 0})); } if(query[j][0] == 3){ que.push({query[j][1], query[j][2]}); while(!que.empty()){ int v = que.front().st; ll d = que.front().nd; que.pop(); color[v] = query[j][3]; myTime[v] = j; while(!events[v].empty() && events[v].back().st <= d)events[v].pop_back(); events[v].push_back({d, {j, query[j][3]}}); for(auto p : compG[v]){ if(myTime[p.st] != j && d - p.nd >= 0){ que.push({p.st, d - p.nd}); } } } //colorDFS(query[j][1], -1, query[j][2], j, query[j][3]); } if(query[j][0] == 4){ int u = query[j][1]; cout<<color[u]<<"\n"; } } for(int v = 1; v <= n; v++){ if(marked[v] && sz(events[v]) > 0){ for(auto p : g[v]){ if(!marked[p.st]){ que1.push({p.st, v, sz(events[v]) - 1, p.nd}); while(!que1.empty()){ int u = get<0>(que1.front()); int prev = get<1>(que1.front()); int ind = get<2>(que1.front()); ll d = get<3>(que1.front()); que1.pop(); while(ind >= 0 && events[v][ind].st < d)ind--; if(ind < 0)continue; if(events[v][ind].nd.st > myTime[u]){ myTime[u] = events[v][ind].nd.st; color[u] = events[v][ind].nd.nd; } for(auto p : g[u]){ if(p.st != prev && !marked[p.st]){ que1.push({p.st, u, ind, d + p.nd}); } } } //updateColor(p.st, v, p.nd, events[v], sz(events[v]) - 1); } } } } for(int v = 1; v <= n; v++){ compG[v].clear(); events[v].clear(); } } return 0; }  | 
            
        
                    English