結果
問題 | No.902 Query ζone |
ユーザー |
![]() |
提出日時 | 2019-10-06 23:22:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,558 bytes |
コンパイル時間 | 2,163 ms |
コンパイル使用メモリ | 207,132 KB |
最終ジャッジ日時 | 2025-01-07 21:11:11 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 TLE * 14 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; template<typename F> struct FixPoint : F{ FixPoint(F&& f):F(forward<F>(f)){} template<typename... Args> decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward<Args>(args)...); } }; template<typename F> inline decltype(auto) MFP(F&& f){ return FixPoint<F>{forward<F>(f)}; } //INSERT ABOVE HERE signed main(){ Int n; cin>>n; vector< map<Int, Int> > G(n); for(Int i=1;i<n;i++){ Int u,v,w; cin>>u>>v>>w; G[u][v]=w; G[v][u]=w; } Int q; cin>>q; for(Int i=0;i<q;i++){ Int t; cin>>t; if(t==1){ Int u,v,w,x; cin>>u>>v>>w>>x; G[u].erase(v); G[v].erase(u); G[v][w]=x; G[w][v]=x; } if(t==2){ Int k; cin>>k; vector<Int> xs(k); for(Int j=0;j<k;j++) cin>>xs[j]; vector<Int> dp(n,-1); for(Int x:xs) dp[x]=0; MFP([&](auto dfs,Int v,Int p)->void{ for(auto e:G[v]){ Int u=e.first,c=e.second; if(u==p) continue; dfs(u,v); if(dp[u]<0) continue; if(dp[v]<0) dp[v]=0; dp[v]+=dp[u]+c; } })(xs[0],-1); cout<<dp[xs[0]]<<"\n"; } } cout<<flush; return 0; }