結果

問題 No.1308 ジャンプビーコン
ユーザー 👑 NachiaNachia
提出日時 2020-12-05 00:34:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,258 bytes
コンパイル時間 2,857 ms
コンパイル使用メモリ 207,024 KB
実行使用メモリ 191,668 KB
最終ジャッジ日時 2023-10-13 12:29:17
合計ジャッジ時間 14,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,704 KB
testcase_01 AC 2 ms
5,724 KB
testcase_02 AC 2 ms
5,840 KB
testcase_03 AC 2 ms
5,808 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
5,756 KB
testcase_24 AC 2 ms
5,976 KB
testcase_25 AC 2 ms
5,812 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 371 ms
191,356 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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

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

int main(){
  scanf("%lld%lld%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){
    queue<int> Q;
    D[s][s]=0; Q.push(s);
    while(Q.size()){
      int p=Q.front(); Q.pop();
      order[s].push_back(p);
      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(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[i]=T[i];
    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