Submission #00124


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define pq priority_queue<P,vector<P>,greater<P>>
const ll inf = 1LL << 60;
struct edge {
int to,c;
};
int main(){
int N,M,C;
cin>>N>>M>>C;
vector<vector<edge>> G(N + 1);
vector<P> e(M);
for(int i = 0;i < M;i++){
int a,b,f;
cin>>a>>b>>f;
G[a].push_back({b,f});
}
vector<ll> dist(N + 1,inf);
dist[1] = 0;
pq q;
q.push(make_pair(0,1));
while(!q.empty()){
P p = q.top();
q.pop();
if(p.first > dist[p.second]) continue;
for(auto i:G[p.second]){
if(dist[i.to] > p.first + i.c){
dist[i.to] = p.first + i.c;
q.push(make_pair(dist[i.to],i.to));
}
}
if(p.second != 1 && dist[p.second - 1] == inf){
dist[p.second - 1]--;
q.push(make_pair(p.first + C,p.second - 1));
}
if(p.second != N && dist[p.second + 1] == inf){
dist[p.second + 1]--;
q.push(make_pair(p.first + C,p.second + 1));
}
}
/* for(int i = 1;i <= N;i++){
if(dist[i] == inf) cout<<"-1 ";
else if(dist[i] == inf - 1) cout<<"-2 ";
else cout<<dist[i]<<" ";
}
cout<<"\n"; */
if(dist[N] == inf-1) cout<<"-1\n";
else cout<<dist[N]<<"\n";
}

ステータス

項目 データ
問題 0010 - テレポート移動網
ユーザー名 r2213
投稿日時 2023-08-28 10:25:21
言語 C++17
状態 Accepted
得点 40
ソースコード長 1438 Byte
最大実行時間 151 ms
最大メモリ使用量 18828 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1 AC 29 ms 604 KB
1
in2 AC 20 ms 720 KB
1
in3 AC 21 ms 7316 KB
1
in4 AC 29 ms 7384 KB
1
in5 AC 21 ms 7356 KB
1
in6 AC 25 ms 7452 KB
1
in7 AC 21 ms 7420 KB
1
in8 AC 23 ms 7388 KB
1
in9 AC 15 ms 7488 KB
1
in10 AC 23 ms 572 KB
1
in11 AC 23 ms 668 KB
1
in12 AC 19 ms 640 KB
1
in13 AC 19 ms 480 KB
1
in14 AC 28 ms 448 KB
1
in15 AC 23 ms 416 KB
1
in16 AC 28 ms 512 KB
1
in17 AC 25 ms 476 KB
1
in18 AC 23 ms 692 KB
1
in19 AC 22 ms 656 KB
1
in20 AC 30 ms 688 KB
1
in21 AC 23 ms 744 KB
1
in22 AC 21 ms 740 KB
1
in23 AC 89 ms 7436 KB
1
in24 AC 130 ms 8852 KB
1
in25 AC 90 ms 13076 KB
1
in26 AC 135 ms 17176 KB
1
in27 AC 25 ms 11944 KB
1
in28 AC 151 ms 18828 KB
1
in29 AC 35 ms 13592 KB
1
in30 AC 25 ms 13556 KB
1
in31 AC 26 ms 13676 KB
1
in32 AC 30 ms 13664 KB
1