結果

問題 No.386 貪欲な領主
ユーザー itezpaceitezpace
提出日時 2016-07-02 00:18:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 894 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 168,184 KB
実行使用メモリ 817,408 KB
最終ジャッジ日時 2024-04-20 21:21:10
合計ジャッジ時間 3,468 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,a,b,u,m,ma,mb,mc;
vector<vector<int>> vn;
vector<int> vc;

int f(int ma, int mb, int x, vector<vector<int>> fn){
  vector<vector<int>> bn;
  bn=fn;
  if(ma==mb){
    return x;
  }
  int y;
  y=0;
  int z;
  z=0;
  for(int i=0; i<n; ++i){
    if(bn[ma][i]==1){
      bn[ma][i]=0;
      bn[i][ma]=0;
      x+=vc[i];
      y+=f(i,mb,x,bn);
    }
  }
  return y;
}

int main(){
  cin>>n;
  vn.resize(n);
  for(int i=0; i<n; ++i){
    vn[i].resize(n);
    for(int j=0; j<n; ++j){
      vn[i][j]=0;
    }
  }
  for(int i=0; i<n-1; ++i){
    cin>>a>>b;
    vn[a][b]=1;
    vn[b][a]=1;
  }
  vc.resize(n);
  for(int i=0; i<n; ++i){
    cin>>u;
    vc[i]=u;
  }
  cin>>m;
  int x,y;
  y=0;
  for(int i=0; i<m; ++i){
    cin>>ma>>mb>>mc;
    x=vc[ma];
    x=f(ma,mb,x,vn);
    x*=mc;
    y+=x;
  }
  cout<<y<<endl;
  return 0;
}
0