Submission #65470


ソースコード

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
#include<bits/stdc++.h>
#define mk(first,second) make_pair(first,second)
#define P pair<int,int>
#define lol long long
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int a,b,c;
vector<P> edges[n+2];//first=繋いだ先のノード second=コスト
for(int i=0;i<m;i++){
cin>>a>>b>>c;
edges[a].push_back(mk(b,c));
edges[b].push_back(mk(a,c));
}
priority_queue<P,vector<P>,greater<P>> pq; //first=コスト second=着目するノード
vector<int> cost(n+10,INT_MAX);
pq.push(mk(0,1));
cost[1]=0;
while(!pq.empty()){
int co = pq.top().first;
int from = pq.top().second;
pq.pop();//忘れない!!
if(co > cost[from]){
continue;
}
for(int i=0;i<edges[from].size();i++){
int to = edges[from][i].first;
int nc = edges[from][i].second;
if(nc + cost[from] < cost[to]){
cost[to] = nc + cost[from];
pq.push(mk(cost[to],to));
}
}
}
if(cost[n] == INT_MAX){
cout<<"NA\n";
}else{
cout<<cost[n]<<"\n";
}
return 0;
}

ステータス

項目 データ
問題 0431 - 君も始めようダイクストラ大好き厨
ユーザー名 ei2038
投稿日時 2021-02-01 17:02:32
言語 C++17
状態 Accepted
得点 1
ソースコード長 1217 Byte
最大実行時間 102 ms
最大メモリ使用量 7000 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
m_in1.txt AC 102 ms 7000 KB
1
r_in1.txt AC 33 ms 1588 KB
1
r_in2.txt AC 43 ms 1500 KB
1
r_in3.txt AC 38 ms 1708 KB
1
r_in4.txt AC 24 ms 1768 KB
1
r_in5.txt AC 44 ms 2160 KB
1
r_in6.txt AC 44 ms 2244 KB
1
r_in7.txt AC 27 ms 1280 KB
1
r_in8.txt AC 29 ms 1392 KB
1
r_in9.txt AC 41 ms 2592 KB
1
r_in10.txt AC 27 ms 1320 KB
1
r_in11.txt AC 40 ms 1572 KB
1
r_in12.txt AC 30 ms 1684 KB
1
r_in13.txt AC 39 ms 1736 KB
1
r_in14.txt AC 35 ms 1816 KB
1
r_in15.txt AC 37 ms 1848 KB
1
r_in16.txt AC 24 ms 1816 KB
1
r_in17.txt AC 32 ms 1820 KB
1
r_in18.txt AC 41 ms 1884 KB
1
r_in19.txt AC 28 ms 728 KB
1
r_in20.txt AC 30 ms 1016 KB
1
r_in21.txt AC 24 ms 704 KB
1
r_in22.txt AC 26 ms 824 KB
1
r_in23.txt AC 37 ms 956 KB
1
r_in24.txt AC 32 ms 1136 KB
1
r_in25.txt AC 30 ms 1224 KB
1
r_in26.txt AC 29 ms 1320 KB
1
r_in27.txt AC 32 ms 1416 KB
1
r_in28.txt AC 31 ms 1464 KB
1
r_in29.txt AC 29 ms 1564 KB
1
r_in30.txt AC 33 ms 1552 KB
1