Submission #65484


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
signed main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n,m,inf=(1LL<<31)-1;
cin>>n>>m;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
vector<int> cost(n+10,inf);
vector<pair<int,int>> edges[n+10];
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
edges[a].push_back(make_pair(b,c));
edges[b].push_back(make_pair(a,c));
}
pq.push(make_pair(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+co<cost[to]){
cost[to]=nc+cost[from];
pq.push(make_pair(cost[to],to));
}
}
}
if(cost[n]==inf){
cout<<"NA"<<'\n';
}
else{
cout<<cost[n]<<'\n';
}
return 0;
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
m_in1.txt AC 69 ms 7000 KB
1
r_in1.txt AC 34 ms 1688 KB
1
r_in2.txt AC 30 ms 1768 KB
1
r_in3.txt AC 41 ms 1740 KB
1
r_in4.txt AC 23 ms 1888 KB
1
r_in5.txt AC 30 ms 2132 KB
1
r_in6.txt AC 27 ms 2324 KB
1
r_in7.txt AC 25 ms 1212 KB
1
r_in8.txt AC 25 ms 1304 KB
1
r_in9.txt AC 34 ms 2476 KB
1
r_in10.txt AC 25 ms 1260 KB
1
r_in11.txt AC 30 ms 1620 KB
1
r_in12.txt AC 28 ms 1584 KB
1
r_in13.txt AC 27 ms 1872 KB
1
r_in14.txt AC 29 ms 1812 KB
1
r_in15.txt AC 31 ms 1820 KB
1
r_in16.txt AC 28 ms 1888 KB
1
r_in17.txt AC 22 ms 2008 KB
1
r_in18.txt AC 25 ms 2060 KB
1
r_in19.txt AC 23 ms 888 KB
1
r_in20.txt AC 34 ms 1012 KB
1
r_in21.txt AC 21 ms 676 KB
1
r_in22.txt AC 24 ms 896 KB
1
r_in23.txt AC 27 ms 1004 KB
1
r_in24.txt AC 21 ms 912 KB
1
r_in25.txt AC 28 ms 1108 KB
1
r_in26.txt AC 30 ms 1312 KB
1
r_in27.txt AC 31 ms 1516 KB
1
r_in28.txt AC 25 ms 1672 KB
1
r_in29.txt AC 30 ms 1624 KB
1
r_in30.txt AC 21 ms 1692 KB
1