/* * @Author: cmk666 * @Created time: 2024-03-15 19:39:30 * @Last Modified time: 2024-03-15 22:13:02 */ #pragma GCC optimize("Ofast", "unroll-loops") #include<bits/stdc++.h> #ifdef LOCAL #include"debug.h" #else #define D(...) ((void)0) #endif using namespace std; using ll = long long; #define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ ) #define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- ) namespace FastIO { // ------------------------------ // #define IN_HAS_NEG // #define OUT_HAS_NEG // #define CHK_EOF #define DISABLE_MMAP // ------------------------------ #if __cplusplus < 201400 #error Please use C++14 or higher. #endif #if __cplusplus > 201700 #define INLINE_V inline #else #define INLINE_V #endif #if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP) #define DISABLE_MMAP #endif #ifndef DISABLE_MMAP #include<sys/mman.h> #endif #ifdef LOCAL inline char gc() { return getchar(); } inline void pc(char c) { putchar(c); } #else #ifdef DISABLE_MMAP INLINE_V constexpr int _READ_SIZE = 1 << 18; INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr; inline char gc() { if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) { _read_ptr = _read_buffer; _read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin); #ifdef CHK_EOF if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF; #endif } return *_read_ptr++; } #else INLINE_V static const char *_read_ptr = (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0); inline char gc() { return *_read_ptr++; } #endif INLINE_V constexpr int _WRITE_SIZE = 1 << 18; INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer; inline void pc(char c) { *_write_ptr++ = c; if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) ) { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); _write_ptr = _write_buffer; } } INLINE_V struct _auto_flush { inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush; #endif #ifdef CHK_EOF inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; } inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; } #else inline constexpr bool _isdigit(char c) { return c & 16; } inline constexpr bool _isgraph(char c) { return c > 32; } #endif template < class T > INLINE_V constexpr bool _is_integer = numeric_limits < T >::is_integer; template < class T > INLINE_V constexpr bool _is_signed = numeric_limits < T >::is_signed; template < class T > INLINE_V constexpr bool _is_unsigned = _is_integer < T > && !_is_signed < T >; template <> INLINE_V constexpr bool _is_integer < __int128 > = true; template <> INLINE_V constexpr bool _is_integer < __uint128_t > = true; template <> INLINE_V constexpr bool _is_signed < __int128 > = true; template <> INLINE_V constexpr bool _is_unsigned < __uint128_t > = true; #undef INLINE_V inline void read(char &c) { do c = gc(); while ( !_isgraph(c) ); } inline void read_cstr(char *s) { char c = gc(); while ( !_isgraph(c) ) c = gc(); while ( _isgraph(c) ) *s++ = c, c = gc(); *s = 0; } inline void read(string &s) { char c = gc(); s.clear(); while ( !_isgraph(c) ) c = gc(); while ( _isgraph(c) ) s.push_back(c), c = gc(); } #ifdef IN_HAS_NEG template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void read(T &x) { char c = gc(); bool f = true; x = 0; while ( !_isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); } if ( f ) while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc(); else while ( _isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc(); } template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > #else template < class T, enable_if_t < _is_integer < T >, int > = 0 > #endif inline void read(T &x) { char c = gc(); while ( !_isdigit(c) ) c = gc(); x = 0; while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc(); } inline void write(char c) { pc(c); } inline void write_cstr(const char *s) { while ( *s ) pc(*s++); } inline void write(const string &s) { for ( char c : s ) pc(c); } #ifdef OUT_HAS_NEG template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void write(T x) { char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0; if ( x >= 0 ) do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x ); else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); } while ( digits ) pc(buffer[--digits]); } template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > #else template < class T, enable_if_t < _is_integer < T >, int > = 0 > #endif inline void write(T x) { char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0; do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x ); while ( digits ) pc(buffer[--digits]); } template < int N > struct _tuple_io_helper { template < class ...T > static inline void _read(tuple < T... > &x) { _tuple_io_helper < N - 1 >::_read(x), read(get < N - 1 > (x)); } template < class ...T > static inline void _write(const tuple < T... > &x) { _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get < N - 1 > (x)); } }; template <> struct _tuple_io_helper < 1 > { template < class ...T > static inline void _read(tuple < T... > &x) { read(get < 0 > (x)); } template < class ...T > static inline void _write(const tuple < T... > &x) { write(get < 0 > (x)); } }; template < class ...T > inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); } template < class ...T > inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); } template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); } template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); } template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); } template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); } template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); } template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); } template < class T > inline void print(const T &x) { write(x); } inline void print_cstr(const char *x) { write_cstr(x); } template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { print(x), pc(32), print(y...); } template < class ...T > inline void print_cstr(const char *x, const T *...y) { print_cstr(x), pc(32), print_cstr(y...); } inline void println() { pc(10); } inline void println_cstr() { pc(10); } template < class ...T > inline void println(const T &...x) { print(x...), pc(10); } template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); } } using namespace FastIO; struct H { inline ll operator()(const auto &x)const { return (ll)x.first << 32 | x.second; } }; int n, m, q, u, v, w, qq, c12, c3, evl, p, vis[200009], t; vector < pair < int, int > > g[200009]; unordered_map < pair < int, int >, int, H > e, es; pair < int, int > ee; tuple < int, pair < int, int >, int > ev[200009]; vector < pair < pair < int, int >, int > > eg[200009]; queue < pair < int, ll > > que; ll dd; struct O { int o, u, v, w; ll d, val; } o[200009]; namespace D { int bel[200009], id, dfn[200009], cnt, st[19][200009]; ll dep[200009]; inline int cmp(int u, int v) { return dfn[u] < dfn[v] ? u : v; } inline void dfs(int u, int id, int fa = 0, ll fw = 0) { bel[u] = id, st[0][dfn[u] = ++cnt] = fa, dep[u] = dep[fa] + fw; for ( auto [i, j] : g[u] ) if ( i != fa ) dfs(i, id, u, j); } inline int build(int u) { int lst = cnt; dfs(u, ++id); int t = __lg(cnt - lst); For(i, 1, t) For(j, lst + 1, cnt + 1 - ( 1 << i )) st[i][j] = cmp(st[i - 1][j], st[i - 1][j + ( 1 << ( i - 1 ) )]); return cnt - lst; } inline int lca(int u, int v) { if ( u == v ) return u; if ( ( u = dfn[u] ) > ( v = dfn[v] ) ) swap(u, v); int t = __lg(v - u++); return cmp(st[t][u], st[t][v + 1 - ( 1 << t )]); } inline ll dis(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } } namespace T { bool vis[200009]; int fa[200009], sz[200009]; vector < pair < ll, ll > > tag[200009]; ll val[200009]; inline void get_rt(int u, int tot, int &mn, int &rt, int fa = 0) { sz[u] = 1; int mx = 0; for ( auto [i, _] : g[u] ) if ( i != fa && !vis[i] ) get_rt(i, tot, mn, rt, u), sz[u] += sz[i], mx = max(mx, sz[i]); if ( ( mx = max(mx, tot - sz[u]) ) < mn ) mn = mx, rt = u; } inline void dfs(int u, int tot, int fa = 0) { int mn = tot, rt = 0; get_rt(u, tot, mn, rt), vis[rt] = true, T::fa[rt] = fa; for ( auto [i, _] : g[rt]) if ( !vis[i] ) dfs(i, sz[i], rt); } inline void mdf(int u, ll d, ll val) { for ( int v = u ; v ; v = fa[v] ) if ( ( dd = d - D::dis(u, v) ) >= 0 ) { for ( ; tag[v].size() && tag[v].back().first <= dd ; tag[v].pop_back() ); tag[v].emplace_back(dd, val); } } inline ll qry(int u) { ll z = val[u]; for ( int v = u ; v ; v = fa[v] ) { auto it = lower_bound(tag[v].begin(), tag[v].end(), pair(D::dis(u, v), 0ll), greater()); if ( it != tag[v].begin() ) z = max(z, prev(it) -> second); } return z; } inline void clear_tag() { For(i, 1, n) val[i] = qry(i); For(i, 1, n) tag[i].clear(); // For(u, 1, n) for ( int v = u ; v ; v = fa[v] ) tag[v].emplace_back(D::dis(u, v), -u); // For(i, 1, n) // { // sort(tag[i].begin(), tag[i].end(), greater()); ll z = 0; // for ( auto [_, j] : tag[i] ) if ( j >= 0 ) z = j; else val[-j] = max(val[-j], z); // tag[i].clear(); // } } } int main() { read(n, m, q); For(i, 1, m) read(u, v, w), e.emplace(minmax(u, v), w); For(_, 1, q) { qq++, read(o[qq].o, o[qq].u); if ( o[qq].o == 1 ) read(o[qq].v, o[qq].w), c12++; else if ( o[qq].o == 2 ) read(o[qq].v), c12++; else if ( o[qq].o == 3 ) read(o[qq].d, o[qq].val), o[qq].val |= (ll)_ << 30, c3++; if ( c12 * c3 >= 1145140 || _ == q ) { decltype(es)().swap(es), evl = 0, p = 1; For(i, 1, qq) if ( o[i].o == 1 ) ev[++evl] = tuple(i, minmax(o[i].u, o[i].v), o[i].w); else if ( o[i].o == 2 ) { ev[++evl] = tuple(i, ee = minmax(o[i].u, o[i].v), 0); if ( e.count(ee) ) es.emplace(ee, e[ee]), e.erase(ee); } For(i, 1, n) g[i].clear(); for ( auto [ee, w] : e ) g[ee.first].emplace_back(ee.second, w), g[ee.second].emplace_back(ee.first, w); D::cnt = D::id = 0, fill(T::vis + 1, T::vis + n + 1, false); For(i, 1, n) if ( !T::vis[i] ) T::dfs(i, D::build(i)); For(i, 1, qq) { for ( ; p <= evl && get<0>(ev[p]) == i ; p++ ) if ( get<2>(ev[p]) ) es.emplace(get<1>(ev[p]), get<2>(ev[p])); else es.erase(get<1>(ev[p])); if ( o[i].o == 3 ) { eg[D::bel[o[i].u]].clear(); for ( auto [ee, w] : es ) eg[D::bel[ee.first]].clear(), eg[D::bel[ee.second]].clear(); for ( auto [ee, w] : es ) eg[D::bel[ee.first]].emplace_back(ee, w), eg[D::bel[ee.second]].emplace_back(pair(ee.second, ee.first), w); for ( vis[D::bel[o[i].u]] = ++t, que.emplace(o[i].u, o[i].d) ; que.size() ; ) { auto [u, d] = que.front(); que.pop(), T::mdf(u, d, o[i].val); for ( auto [ee, w] : eg[D::bel[u]] ) if ( vis[D::bel[ee.second]] != t ) if ( ( dd = d - D::dis(u, ee.first) - w ) >= 0 ) vis[D::bel[ee.second]] = t, que.emplace(ee.second, dd); } } else if ( o[i].o == 4 ) println(T::qry(o[i].u) & 1073741823); } if ( _ != q ) { T::clear_tag(), qq = c12 = c3 = 0; for ( auto [ee, w] : es ) e.emplace(ee, w); } } } return 0; } // 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏 // 伊娜可爱捏 伊娜贴贴捏
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | /* * @Author: cmk666 * @Created time: 2024-03-15 19:39:30 * @Last Modified time: 2024-03-15 22:13:02 */ #pragma GCC optimize("Ofast", "unroll-loops") #include<bits/stdc++.h> #ifdef LOCAL #include"debug.h" #else #define D(...) ((void)0) #endif using namespace std; using ll = long long; #define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ ) #define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- ) namespace FastIO { // ------------------------------ // #define IN_HAS_NEG // #define OUT_HAS_NEG // #define CHK_EOF #define DISABLE_MMAP // ------------------------------ #if __cplusplus < 201400 #error Please use C++14 or higher. #endif #if __cplusplus > 201700 #define INLINE_V inline #else #define INLINE_V #endif #if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP) #define DISABLE_MMAP #endif #ifndef DISABLE_MMAP #include<sys/mman.h> #endif #ifdef LOCAL inline char gc() { return getchar(); } inline void pc(char c) { putchar(c); } #else #ifdef DISABLE_MMAP INLINE_V constexpr int _READ_SIZE = 1 << 18; INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr; inline char gc() { if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) { _read_ptr = _read_buffer; _read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin); #ifdef CHK_EOF if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF; #endif } return *_read_ptr++; } #else INLINE_V static const char *_read_ptr = (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0); inline char gc() { return *_read_ptr++; } #endif INLINE_V constexpr int _WRITE_SIZE = 1 << 18; INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer; inline void pc(char c) { *_write_ptr++ = c; if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) ) { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); _write_ptr = _write_buffer; } } INLINE_V struct _auto_flush { inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush; #endif #ifdef CHK_EOF inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; } inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; } #else inline constexpr bool _isdigit(char c) { return c & 16; } inline constexpr bool _isgraph(char c) { return c > 32; } #endif template < class T > INLINE_V constexpr bool _is_integer = numeric_limits < T >::is_integer; template < class T > INLINE_V constexpr bool _is_signed = numeric_limits < T >::is_signed; template < class T > INLINE_V constexpr bool _is_unsigned = _is_integer < T > && !_is_signed < T >; template <> INLINE_V constexpr bool _is_integer < __int128 > = true; template <> INLINE_V constexpr bool _is_integer < __uint128_t > = true; template <> INLINE_V constexpr bool _is_signed < __int128 > = true; template <> INLINE_V constexpr bool _is_unsigned < __uint128_t > = true; #undef INLINE_V inline void read(char &c) { do c = gc(); while ( !_isgraph(c) ); } inline void read_cstr(char *s) { char c = gc(); while ( !_isgraph(c) ) c = gc(); while ( _isgraph(c) ) *s++ = c, c = gc(); *s = 0; } inline void read(string &s) { char c = gc(); s.clear(); while ( !_isgraph(c) ) c = gc(); while ( _isgraph(c) ) s.push_back(c), c = gc(); } #ifdef IN_HAS_NEG template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void read(T &x) { char c = gc(); bool f = true; x = 0; while ( !_isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); } if ( f ) while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc(); else while ( _isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc(); } template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > #else template < class T, enable_if_t < _is_integer < T >, int > = 0 > #endif inline void read(T &x) { char c = gc(); while ( !_isdigit(c) ) c = gc(); x = 0; while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc(); } inline void write(char c) { pc(c); } inline void write_cstr(const char *s) { while ( *s ) pc(*s++); } inline void write(const string &s) { for ( char c : s ) pc(c); } #ifdef OUT_HAS_NEG template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void write(T x) { char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0; if ( x >= 0 ) do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x ); else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); } while ( digits ) pc(buffer[--digits]); } template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > #else template < class T, enable_if_t < _is_integer < T >, int > = 0 > #endif inline void write(T x) { char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0; do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x ); while ( digits ) pc(buffer[--digits]); } template < int N > struct _tuple_io_helper { template < class ...T > static inline void _read(tuple < T... > &x) { _tuple_io_helper < N - 1 >::_read(x), read(get < N - 1 > (x)); } template < class ...T > static inline void _write(const tuple < T... > &x) { _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get < N - 1 > (x)); } }; template <> struct _tuple_io_helper < 1 > { template < class ...T > static inline void _read(tuple < T... > &x) { read(get < 0 > (x)); } template < class ...T > static inline void _write(const tuple < T... > &x) { write(get < 0 > (x)); } }; template < class ...T > inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); } template < class ...T > inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); } template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); } template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); } template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); } template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); } template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); } template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); } template < class T > inline void print(const T &x) { write(x); } inline void print_cstr(const char *x) { write_cstr(x); } template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { print(x), pc(32), print(y...); } template < class ...T > inline void print_cstr(const char *x, const T *...y) { print_cstr(x), pc(32), print_cstr(y...); } inline void println() { pc(10); } inline void println_cstr() { pc(10); } template < class ...T > inline void println(const T &...x) { print(x...), pc(10); } template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); } } using namespace FastIO; struct H { inline ll operator()(const auto &x)const { return (ll)x.first << 32 | x.second; } }; int n, m, q, u, v, w, qq, c12, c3, evl, p, vis[200009], t; vector < pair < int, int > > g[200009]; unordered_map < pair < int, int >, int, H > e, es; pair < int, int > ee; tuple < int, pair < int, int >, int > ev[200009]; vector < pair < pair < int, int >, int > > eg[200009]; queue < pair < int, ll > > que; ll dd; struct O { int o, u, v, w; ll d, val; } o[200009]; namespace D { int bel[200009], id, dfn[200009], cnt, st[19][200009]; ll dep[200009]; inline int cmp(int u, int v) { return dfn[u] < dfn[v] ? u : v; } inline void dfs(int u, int id, int fa = 0, ll fw = 0) { bel[u] = id, st[0][dfn[u] = ++cnt] = fa, dep[u] = dep[fa] + fw; for ( auto [i, j] : g[u] ) if ( i != fa ) dfs(i, id, u, j); } inline int build(int u) { int lst = cnt; dfs(u, ++id); int t = __lg(cnt - lst); For(i, 1, t) For(j, lst + 1, cnt + 1 - ( 1 << i )) st[i][j] = cmp(st[i - 1][j], st[i - 1][j + ( 1 << ( i - 1 ) )]); return cnt - lst; } inline int lca(int u, int v) { if ( u == v ) return u; if ( ( u = dfn[u] ) > ( v = dfn[v] ) ) swap(u, v); int t = __lg(v - u++); return cmp(st[t][u], st[t][v + 1 - ( 1 << t )]); } inline ll dis(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } } namespace T { bool vis[200009]; int fa[200009], sz[200009]; vector < pair < ll, ll > > tag[200009]; ll val[200009]; inline void get_rt(int u, int tot, int &mn, int &rt, int fa = 0) { sz[u] = 1; int mx = 0; for ( auto [i, _] : g[u] ) if ( i != fa && !vis[i] ) get_rt(i, tot, mn, rt, u), sz[u] += sz[i], mx = max(mx, sz[i]); if ( ( mx = max(mx, tot - sz[u]) ) < mn ) mn = mx, rt = u; } inline void dfs(int u, int tot, int fa = 0) { int mn = tot, rt = 0; get_rt(u, tot, mn, rt), vis[rt] = true, T::fa[rt] = fa; for ( auto [i, _] : g[rt]) if ( !vis[i] ) dfs(i, sz[i], rt); } inline void mdf(int u, ll d, ll val) { for ( int v = u ; v ; v = fa[v] ) if ( ( dd = d - D::dis(u, v) ) >= 0 ) { for ( ; tag[v].size() && tag[v].back().first <= dd ; tag[v].pop_back() ); tag[v].emplace_back(dd, val); } } inline ll qry(int u) { ll z = val[u]; for ( int v = u ; v ; v = fa[v] ) { auto it = lower_bound(tag[v].begin(), tag[v].end(), pair(D::dis(u, v), 0ll), greater()); if ( it != tag[v].begin() ) z = max(z, prev(it) -> second); } return z; } inline void clear_tag() { For(i, 1, n) val[i] = qry(i); For(i, 1, n) tag[i].clear(); // For(u, 1, n) for ( int v = u ; v ; v = fa[v] ) tag[v].emplace_back(D::dis(u, v), -u); // For(i, 1, n) // { // sort(tag[i].begin(), tag[i].end(), greater()); ll z = 0; // for ( auto [_, j] : tag[i] ) if ( j >= 0 ) z = j; else val[-j] = max(val[-j], z); // tag[i].clear(); // } } } int main() { read(n, m, q); For(i, 1, m) read(u, v, w), e.emplace(minmax(u, v), w); For(_, 1, q) { qq++, read(o[qq].o, o[qq].u); if ( o[qq].o == 1 ) read(o[qq].v, o[qq].w), c12++; else if ( o[qq].o == 2 ) read(o[qq].v), c12++; else if ( o[qq].o == 3 ) read(o[qq].d, o[qq].val), o[qq].val |= (ll)_ << 30, c3++; if ( c12 * c3 >= 1145140 || _ == q ) { decltype(es)().swap(es), evl = 0, p = 1; For(i, 1, qq) if ( o[i].o == 1 ) ev[++evl] = tuple(i, minmax(o[i].u, o[i].v), o[i].w); else if ( o[i].o == 2 ) { ev[++evl] = tuple(i, ee = minmax(o[i].u, o[i].v), 0); if ( e.count(ee) ) es.emplace(ee, e[ee]), e.erase(ee); } For(i, 1, n) g[i].clear(); for ( auto [ee, w] : e ) g[ee.first].emplace_back(ee.second, w), g[ee.second].emplace_back(ee.first, w); D::cnt = D::id = 0, fill(T::vis + 1, T::vis + n + 1, false); For(i, 1, n) if ( !T::vis[i] ) T::dfs(i, D::build(i)); For(i, 1, qq) { for ( ; p <= evl && get<0>(ev[p]) == i ; p++ ) if ( get<2>(ev[p]) ) es.emplace(get<1>(ev[p]), get<2>(ev[p])); else es.erase(get<1>(ev[p])); if ( o[i].o == 3 ) { eg[D::bel[o[i].u]].clear(); for ( auto [ee, w] : es ) eg[D::bel[ee.first]].clear(), eg[D::bel[ee.second]].clear(); for ( auto [ee, w] : es ) eg[D::bel[ee.first]].emplace_back(ee, w), eg[D::bel[ee.second]].emplace_back(pair(ee.second, ee.first), w); for ( vis[D::bel[o[i].u]] = ++t, que.emplace(o[i].u, o[i].d) ; que.size() ; ) { auto [u, d] = que.front(); que.pop(), T::mdf(u, d, o[i].val); for ( auto [ee, w] : eg[D::bel[u]] ) if ( vis[D::bel[ee.second]] != t ) if ( ( dd = d - D::dis(u, ee.first) - w ) >= 0 ) vis[D::bel[ee.second]] = t, que.emplace(ee.second, dd); } } else if ( o[i].o == 4 ) println(T::qry(o[i].u) & 1073741823); } if ( _ != q ) { T::clear_tag(), qq = c12 = c3 = 0; for ( auto [ee, w] : es ) e.emplace(ee, w); } } } return 0; } // 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏 // 伊娜可爱捏 伊娜贴贴捏 |