Submission #17584
ソースコード
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 | #include<bits/stdc++.h> using namespace std; struct NODE{ int to,cost,ticnum; NODE( int to, int cost, int ticnum) : to(to),cost(cost),ticnum(ticnum){} NODE(){} bool operator < ( const NODE &a) const { return cost > a.cost; } }; int main(){ int c,n,m,s,d; cin >> c >> n >> m >> s >> d; vector<NODE> edge[100001]; int a,b,f; for ( int i=0;i<m;i++){ cin >> a >> b >> f; edge[a].push_back(NODE(b,f,0)); edge[b].push_back(NODE(a,f,0)); edge[a].push_back(NODE(b,f/2,1)); edge[b].push_back(NODE(a,f/2,1)); } bool done[501][11] = {}; priority_queue<NODE> Q; Q.push(NODE(s,0,0)); while (!Q.empty()){ NODE q = Q.top();Q.pop(); if (done[q.to][q.ticnum]) continue ; if (q.ticnum > c) continue ; done[q.to][q.ticnum] = true ; if (q.to == d){ cout << q.cost << endl; break ; } for ( int i=0;i<edge[q.to].size();i++){ Q.push(NODE(edge[q.to][i].to,q.cost + edge[q.to][i].cost,q.ticnum + edge[q.to][i].ticnum)); } } } |
ステータス
項目 | データ |
---|---|
問題 | 0717 - 高速バス |
ユーザー名 | ei1506 |
投稿日時 | 2017-05-15 17:52:31 |
言語 | C++11 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 918 Byte |
最大実行時間 | 24 ms |
最大メモリ使用量 | 3036 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01.txt | AC | 12 ms | 2784 KB |
1
|
input02.txt | AC | 10 ms | 2932 KB |
1
|
input03.txt | AC | 12 ms | 2972 KB |
1
|
input04.txt | AC | 15 ms | 2856 KB |
1
|
input05.txt | AC | 13 ms | 2860 KB |
1
|
input06.txt | AC | 17 ms | 2844 KB |
1
|
input07.txt | AC | 24 ms | 2988 KB |
1
|
input08.txt | AC | 22 ms | 3036 KB |
1
|
input09.txt | AC | 13 ms | 2872 KB |
1
|
input10.txt | AC | 13 ms | 2860 KB |
1
|