結果

問題 No.1308 ジャンプビーコン
ユーザー 👑 NachiaNachia
提出日時 2020-12-05 00:40:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 574 ms / 4,000 ms
コード長 1,246 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 204,992 KB
実行使用メモリ 191,616 KB
最終ジャッジ日時 2023-10-13 12:36:31
合計ジャッジ時間 12,654 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,740 KB
testcase_01 AC 3 ms
5,852 KB
testcase_02 AC 2 ms
5,704 KB
testcase_03 AC 2 ms
5,760 KB
testcase_04 AC 2 ms
5,760 KB
testcase_05 AC 2 ms
5,844 KB
testcase_06 AC 2 ms
5,756 KB
testcase_07 AC 2 ms
5,796 KB
testcase_08 AC 2 ms
5,812 KB
testcase_09 AC 3 ms
5,864 KB
testcase_10 AC 3 ms
5,812 KB
testcase_11 AC 2 ms
5,784 KB
testcase_12 AC 2 ms
5,844 KB
testcase_13 AC 10 ms
14,660 KB
testcase_14 AC 10 ms
14,616 KB
testcase_15 AC 11 ms
14,616 KB
testcase_16 AC 10 ms
14,788 KB
testcase_17 AC 10 ms
14,576 KB
testcase_18 AC 521 ms
191,404 KB
testcase_19 AC 490 ms
191,324 KB
testcase_20 AC 509 ms
191,396 KB
testcase_21 AC 505 ms
191,472 KB
testcase_22 AC 495 ms
191,348 KB
testcase_23 AC 2 ms
5,732 KB
testcase_24 AC 2 ms
5,708 KB
testcase_25 AC 2 ms
5,708 KB
testcase_26 AC 410 ms
191,316 KB
testcase_27 AC 423 ms
191,356 KB
testcase_28 AC 410 ms
191,396 KB
testcase_29 AC 439 ms
191,616 KB
testcase_30 AC 468 ms
191,464 KB
testcase_31 AC 362 ms
191,432 KB
testcase_32 AC 456 ms
191,424 KB
testcase_33 AC 499 ms
191,412 KB
testcase_34 AC 416 ms
191,372 KB
testcase_35 AC 411 ms
191,384 KB
testcase_36 AC 430 ms
191,384 KB
testcase_37 AC 437 ms
191,324 KB
testcase_38 AC 568 ms
191,364 KB
testcase_39 AC 574 ms
191,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0;i<(n);i++)

const LL INF = 1000000000000000000;

struct Edge{ int to; LL d;};

int N,Q; LL C;
vector<Edge> E[3000];
int X[3000];
LL D[3000][3000];
LL P[3000][3000];
vector<int> order[3000];

int main(){
  scanf("%d%d%lld",&N,&Q,&C);
  rep(i,N-1){
    int u,v; LL d; scanf("%d%d%lld",&u,&v,&d); u--; v--;
    E[u].push_back({v,d});
    E[v].push_back({u,d});
  }
  rep(i,Q){ scanf("%d",&X[i]); X[i]--; }

  rep(i,N) rep(j,N) D[i][j]=P[i][j]=-1;
  rep(s,N){
    auto& Q = order[s];
    D[s][s]=0; Q.push_back(s);
    for(int i=0; i<Q.size(); i++){
      int p=Q[i];
      for(Edge e:E[p]){
        if(D[s][e.to]!=-1) continue;
        D[s][e.to] = D[s][p] + e.d;
        P[s][e.to] = p;
        Q.push_back(e.to);
      }
    }
  }

  LL T[3000]; rep(i,N) T[i]=INF;
  T[X[0]]=0;

  rep(i,Q-1){
    int s=X[i], t=X[i+1];
    LL buf[3000]; rep(i,N) buf[i]=T[i]+C;
    buf[s]=T[s];
    for(int p:order[s]) for(Edge e:E[p]){
      buf[e.to] = min(buf[e.to],buf[p]+e.d);
    }
    rep(i,N) buf[i]+=D[i][t];
    rep(i,N) buf[i]=min(buf[i],T[i]+D[s][t]);
    rep(i,N) T[i]=buf[i];
  }

  printf("%lld\n",T[X[Q-1]]);

  return 0;
}
0