Submission #21427


ソースコード

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
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int INF=1<<30;
typedef pair<int,int>P;
typedef pair<int,P>Bus;
int min_cost[1000][1000];
vector<P>node[1000];
int main(){
int n,m;
int ticket;
int s,g;
cin>>ticket>>n>>m;
cin>>s>>g;
for(int i=0;i<=n;i++){
for(int j=0;j<=ticket;j++){
min_cost[i][j]=INF;
}
}
for(int i=0;i<m;i++){
int a,b,fee;
cin>>a>>b>>fee;
node[a].push_back(P(b,fee));
node[b].push_back(P(a,fee));
}
priority_queue<Bus,vector<Bus>,greater<Bus> >pq;
pq.push(Bus(0,P(s,ticket)));
while(!pq.empty()){
Bus bus=pq.top();pq.pop();
int cost=bus.first;
int pos=bus.second.first;
int t=bus.second.second;
for(int i=0;i<node[pos].size();i++){
int next=node[pos][i].first;
int ncost=node[pos][i].second;
if(cost+ncost<min_cost[next][t]){
min_cost[next][t]=cost+ncost;
pq.push(Bus(min_cost[next][t],P(next,t)));
}
if(t>0){
ncost/=2;
if(cost+ncost<min_cost[next][t-1]){
min_cost[next][t-1]=cost+ncost;
pq.push(Bus(min_cost[next][t-1],P(next,t-1)));
}
}
}
}
int minimum=INF;
for(int i=0;i<=ticket;i++){
minimum=min(min_cost[g][i],minimum);
}
cout<<minimum<<endl;
return(0);
}

ステータス

項目 データ
問題 0717 - 高速バス
ユーザー名 ei1630
投稿日時 2017-07-12 18:17:40
言語 C++11
状態 Accepted
得点 5
ソースコード長 1308 Byte
最大実行時間 36 ms
最大メモリ使用量 1060 KB

セット

セット 得点 Cases
1 ALL 5 / 5 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input01.txt AC 16 ms 864 KB
1
input02.txt AC 11 ms 536 KB
1
input03.txt AC 14 ms 840 KB
1
input04.txt AC 13 ms 916 KB
1
input05.txt AC 13 ms 864 KB
1
input06.txt AC 36 ms 1000 KB
1
input07.txt AC 15 ms 1044 KB
1
input08.txt AC 15 ms 1060 KB
1
input09.txt AC 11 ms 820 KB
1
input10.txt AC 15 ms 488 KB
1