Submission #40689


ソースコード

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
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define COLD 0
#define HOT 1
#define NORMAL 2
using namespace std;
typedef pair<int,int>P;
typedef pair<P,P>Snake;
const int INF=1<<30;
int min_cost[10005][205][2];
int main(){
int n,m,limit;
int thermo[10005];
vector<P>node[10005];
cin>>n>>m>>limit;
for(int i=0;i<=n;i++){
for(int j=0;j<205;j++){
for(int k=0;k<2;k++){
min_cost[i][j][k]=INF;
}
}
}
for(int i=1;i<=n;i++){
int state;
cin>>state;
if(state==0){
thermo[i]=COLD;
}else if(state==1){
thermo[i]=NORMAL;
}else if(state==2){
thermo[i]=HOT;
}
}
for(int i=0;i<m;i++){
int a,b,cost;
cin>>a>>b>>cost;
node[a].push_back(P(b,cost));
node[b].push_back(P(a,cost));
}
priority_queue<Snake,vector<Snake>,greater<Snake> >pq;
pq.push(Snake(P(0,1),P(limit,COLD)));
while(!pq.empty()){
Snake now=pq.top();pq.pop();
int cost=now.first.first;
int pos=now.first.second;
int lim=now.second.first;
int state=now.second.second;
for(int i=0;i<node[pos].size();i++){
int next=node[pos][i].first;
int ncost=node[pos][i].second+cost;
int nlim=max(0,lim-node[pos][i].second);
if(thermo[next]==NORMAL){
if(ncost<min_cost[next][nlim][state]){
min_cost[next][nlim][state]=ncost;
pq.push(Snake(P(ncost,next),P(nlim,state)));
}
}else if(thermo[next]==state){
if(ncost<min_cost[next][limit][state]){
min_cost[next][limit][state]=ncost;
pq.push(Snake(P(ncost,next),P(limit,state)));
}
}else if(nlim<=0){
if(ncost<min_cost[next][limit][thermo[next]]){
min_cost[next][limit][thermo[next]]=ncost;
pq.push(Snake(P(ncost,next),P(limit,thermo[next])));
}
}
}
}
int minimum=INF;
for(int i=0;i<205;i++){
for(int j=0;j<2;j++){
minimum=min(minimum,min_cost[n][i][j]);
}
}
cout<<minimum<<endl;
return(0);
}

ステータス

項目 データ
問題 0597 - ヘビの JOI 君 (Snake JOI)
ユーザー名 ei1630
投稿日時 2018-08-06 11:22:39
言語 C++11
状態 Accepted
得点 100
ソースコード長 2020 Byte
最大実行時間 104 ms
最大メモリ使用量 18996 KB

セット

セット 得点 Cases
1 set1 20 / 20 *t6*1.txt
2 set2 20 / 20 *t6*2.txt
3 set3 20 / 20 *t6*3.txt
4 set4 20 / 20 *t6*4.txt
5 set5 20 / 20 *t6*5.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
2017-yo-t6-in1.txt AC 104 ms 15968 KB
1
2017-yo-t6-in2.txt AC 81 ms 16224 KB
2
2017-yo-t6-in3.txt AC 62 ms 18256 KB
3
2017-yo-t6-in4.txt AC 66 ms 18788 KB
4
2017-yo-t6-in5.txt AC 69 ms 18996 KB
5