Submission #28819


ソースコード

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

ステータス

項目 データ
問題 0597 - ヘビの JOI 君 (Snake JOI)
ユーザー名 ei1630
投稿日時 2017-11-19 16:21:46
言語 C++11
状態 Accepted
得点 100
ソースコード長 1937 Byte
最大実行時間 62 ms
最大メモリ使用量 17364 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 62 ms 11212 KB
1
2017-yo-t6-in2.txt AC 47 ms 13416 KB
2
2017-yo-t6-in3.txt AC 54 ms 16676 KB
3
2017-yo-t6-in4.txt AC 62 ms 17000 KB
4
2017-yo-t6-in5.txt AC 54 ms 17364 KB
5