結果
問題 | No.1308 ジャンプビーコン |
ユーザー | milanis48663220 |
提出日時 | 2020-12-05 02:07:52 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 310 ms / 4,000 ms |
コード長 | 2,121 bytes |
コンパイル時間 | 846 ms |
コンパイル使用メモリ | 98,676 KB |
実行使用メモリ | 74,340 KB |
最終ジャッジ日時 | 2023-10-13 13:05:21 |
合計ジャッジ時間 | 6,963 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 1 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
5,872 KB |
testcase_04 | AC | 2 ms
5,872 KB |
testcase_05 | AC | 2 ms
5,840 KB |
testcase_06 | AC | 2 ms
5,920 KB |
testcase_07 | AC | 2 ms
5,952 KB |
testcase_08 | AC | 5 ms
14,092 KB |
testcase_09 | AC | 4 ms
14,056 KB |
testcase_10 | AC | 4 ms
14,060 KB |
testcase_11 | AC | 4 ms
14,056 KB |
testcase_12 | AC | 4 ms
14,080 KB |
testcase_13 | AC | 25 ms
57,676 KB |
testcase_14 | AC | 23 ms
20,148 KB |
testcase_15 | AC | 24 ms
62,404 KB |
testcase_16 | AC | 24 ms
20,392 KB |
testcase_17 | AC | 21 ms
20,144 KB |
testcase_18 | AC | 230 ms
74,104 KB |
testcase_19 | AC | 235 ms
74,096 KB |
testcase_20 | AC | 241 ms
74,096 KB |
testcase_21 | AC | 241 ms
74,120 KB |
testcase_22 | AC | 238 ms
74,104 KB |
testcase_23 | AC | 2 ms
4,352 KB |
testcase_24 | AC | 16 ms
64,824 KB |
testcase_25 | AC | 15 ms
57,964 KB |
testcase_26 | AC | 175 ms
74,116 KB |
testcase_27 | AC | 169 ms
74,100 KB |
testcase_28 | AC | 171 ms
74,092 KB |
testcase_29 | AC | 207 ms
74,340 KB |
testcase_30 | AC | 207 ms
74,240 KB |
testcase_31 | AC | 188 ms
74,216 KB |
testcase_32 | AC | 205 ms
74,272 KB |
testcase_33 | AC | 295 ms
74,304 KB |
testcase_34 | AC | 174 ms
74,128 KB |
testcase_35 | AC | 174 ms
74,100 KB |
testcase_36 | AC | 177 ms
74,156 KB |
testcase_37 | AC | 177 ms
74,324 KB |
testcase_38 | AC | 302 ms
74,120 KB |
testcase_39 | AC | 310 ms
74,148 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; struct edge{ int to; ll cost; }; const ll INF = 1e16; int n, q; ll c; int x[3000]; vector<edge> G[3000]; ll dp[3005][3005]; void input(){ cin >> n >> q >> c; for(int i = 0; i < n-1; i++){ int u, v; ll l; cin >> u >> v >> l; u--; v--; G[u].push_back((edge){v, l}); G[v].push_back((edge){u, l}); } for(int i = 0; i < q; i++) { cin >> x[i]; x[i]--; } for(int i = 0; i < q; i++){ for(int j = 0; j < n; j++){ dp[i][j] = INF; } } } ll dist[3000]; ll cost[3000]; bool used[3000]; void clear(){ for(int i = 0; i < n; i++) used[i] = false; } // x[idx]に行こうとしている ll dfs(int v, int idx){ used[v] = true; ll ans = INF; for(edge e: G[v]){ if(!used[e.to]){ dist[e.to] = dist[v]+e.cost; chmin(ans, dfs(e.to, idx)); } } chmin(ans, cost[v]+dist[v]); chmin(dp[idx][v], ans); return ans; } void solve(){ dp[0][x[0]] = 0; for(int i = 1; i < q; i++){ clear(); for(int j = 0; j < n; j++){ if(j != x[i-1]){ cost[j] = dp[i-1][j]+c; }else{ cost[j] = dp[i-1][j]; } } dist[x[i]] = 0; dfs(x[i], i); for(int j = 0; j < n; j++){ chmin(dp[i][j], dp[i-1][j]+dist[x[i-1]]); } } cout << dp[q-1][x[q-1]] << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; input(); solve(); }