結果
問題 | No.2439 Fragile Apple Tree |
ユーザー | 👑 potato167 |
提出日時 | 2023-08-16 01:23:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,293 bytes |
コンパイル時間 | 2,926 ms |
コンパイル使用メモリ | 223,236 KB |
実行使用メモリ | 63,756 KB |
最終ジャッジ日時 | 2024-05-03 11:13:19 |
合計ジャッジ時間 | 19,781 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 176 ms
63,756 KB |
testcase_01 | AC | 392 ms
34,112 KB |
testcase_02 | AC | 390 ms
34,000 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
#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"; } } }