結果

問題 No.902 Query ζone
ユーザー beetbeet
提出日時 2019-10-06 23:22:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,558 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 208,160 KB
実行使用メモリ 28,196 KB
最終ジャッジ日時 2024-04-20 01:01:19
合計ジャッジ時間 9,385 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0