結果

問題 No.1308 ジャンプビーコン
ユーザー 👑 NachiaNachia
提出日時 2020-12-05 00:34:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,258 bytes
コンパイル時間 2,402 ms
コンパイル使用メモリ 200,976 KB
最終ジャッジ日時 2025-01-16 16:26:23
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |   scanf("%lld%lld%lld",&N,&Q,&C);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     int u,v; LL d; scanf("%d%d%lld",&u,&v,&d); u--; v--;
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:25:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   rep(i,Q){ scanf("%d",&X[i]); X[i]--; }
      |             ~~~~~^~~~~~~~~~~~

ソースコード

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