Submission #17063
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include<bits/stdc++.h> using namespace std; const int INF = 1000000000; struct Edge{ int to,cost; }; struct Node{ int val,num; }; struct P{ int val,num,c; bool operator<( const P &r) const { return val < r.val; } }; vector<Edge>edge[105]; Node node[11][105]; priority_queue<P> que; int main(){ int c,n,m,s,d; cin >> c >> n >> m >> s >> d; s--;d--; for ( int i = 0; i < m; i++){ int a,b,c; cin >> a >> b >> c; a--;b--; edge[a].push_back((Edge){b,c}); edge[b].push_back((Edge){a,c}); } for ( int i = 0; i < 11; i++){ for ( int j = 0; j < n; j++){ node[i][j].val = INF; node[i][j].num = j; } } node[c][s].val = 0; que.push((P){0,s,c}); while (!que.empty()){ int val = que.top().val; int now = que.top().num; int ticket = que.top().c; que.pop(); if (ticket){ for ( int i = 0; i < edge[now].size(); i++){ int next = edge[now][i].to; int cost = edge[now][i].cost; if (node[ticket - 1][next].val > node[ticket][now].val + cost / 2){ node[ticket - 1][next].val = node[ticket][now].val + cost / 2; que.push((P){node[ticket - 1][next].val,next,ticket - 1}); } } } for ( int i = 0; i < edge[now].size(); i++){ int next = edge[now][i].to; int cost = edge[now][i].cost; if (node[ticket][next].val > node[ticket][now].val + cost){ node[ticket][next].val = node[ticket][now].val + cost; que.push((P){node[ticket][next].val,next,ticket}); } } } int ans = INF; for ( int i = 0; i < c; i++){ ans = min(ans,node[i][d].val); } cout << ans << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0717 - 高速バス |
ユーザー名 | ei1501 |
投稿日時 | 2017-05-11 16:41:15 |
言語 | C++11 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1712 Byte |
最大実行時間 | 38 ms |
最大メモリ使用量 | 664 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01.txt | AC | 14 ms | 480 KB |
1
|
input02.txt | AC | 11 ms | 432 KB |
1
|
input03.txt | AC | 16 ms | 516 KB |
1
|
input04.txt | AC | 20 ms | 596 KB |
1
|
input05.txt | AC | 38 ms | 664 KB |
1
|
input06.txt | AC | 13 ms | 480 KB |
1
|
input07.txt | AC | 30 ms | 540 KB |
1
|
input08.txt | AC | 36 ms | 604 KB |
1
|
input09.txt | AC | 13 ms | 664 KB |
1
|
input10.txt | AC | 14 ms | 604 KB |
1
|