結果
問題 |
No.2439 Fragile Apple Tree
|
ユーザー |
👑 ![]() |
提出日時 | 2023-08-16 01:23:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,293 bytes |
コンパイル時間 | 2,610 ms |
コンパイル使用メモリ | 221,664 KB |
最終ジャッジ日時 | 2025-02-16 08:36:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 TLE * 1 -- * 26 |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; using ll = long long; #define all(p) p.begin(),p.end() #define rep(i,a,b) for(int i=(int)a;i<(int)b;i++) const int mod=998244353; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin>>N>>Q; vector<int> A(N-1),B(N-1); vector<ll> C(N-1); vector<vector<int>> G(N); rep(i,0,N-1){ cin>>A[i]>>B[i]>>C[i]; A[i]--,B[i]--; G[A[i]].push_back(B[i]); G[B[i]].push_back(A[i]); } vector<int> order={0},depth(N),wei(N),pare(N,-1); pare[0]=-2; rep(i,0,N){ int a=order[i]; for(auto b:G[a]){ if(pare[b]==-1){ pare[b]=a; order.push_back(b); depth[b]=depth[a]+1; } } } rep(i,0,N){ int a=order[N-i-1]; for(auto b:G[a]){ if(pare[b]==a) wei[a]+=wei[b]; } wei[a]++; } vector<ll> n_C(N),V(N); rep(i,0,N-1){ if(depth[A[i]]>depth[B[i]]) swap(A[i],B[i]); n_C[B[i]]=C[i]; } swap(n_C,C); rep(rp,0,Q){ int t; cin>>t; if(t==1){ int u; ll x; cin>>u>>x; u--; while(u){ V[u]+=x; if(C[u]<=V[u]){ int tmp=u; while(u){ u=pare[u]; V[u]+=x; V[u]-=V[tmp]; wei[u]-=wei[tmp]; } break; } u=pare[u]; } } if(t==2){ cout<<wei[0]<<"\n"; } } }