結果
問題 |
No.1308 ジャンプビーコン
|
ユーザー |
👑 ![]() |
提出日時 | 2020-12-05 00:40:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 632 ms / 4,000 ms |
コード長 | 1,246 bytes |
コンパイル時間 | 2,595 ms |
コンパイル使用メモリ | 199,004 KB |
最終ジャッジ日時 | 2025-01-16 16:29:46 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
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("%d%d%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]--; } | ~~~~~^~~~~~~~~~~~
ソースコード
#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; }