Submission #64958


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mk(f,s) make_pair(f,s)
#define P pair<int,int>
#define f first
#define s second
#define lol long long
int main(){
int n,m;
cin>>n>>m;
vector<P> edges[n+10];
for(int i=0;i<m;i++){
int a,b,c;
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;
vector<int> cost(n+10,inf);
pq.push(mk(0,1));
while(!pq.empty()){
int co = pq.top().f;
int from = pq.top().s;
pq.pop();
if(co > cost[from]){
continue;
}
for(int i=0;i<edges[from].size();i++){
int to = edges[from][i].f;
int nc = co + edges[from][i].s;
if(nc < cost[to]){
cost[to] = nc;
pq.push(mk(nc,to));
}
}
}
if(cost[n] == inf){
cout<<"NA\n";
}else{
cout<<cost[n]<<"\n";
}
return(0);
}

ステータス

項目 データ
問題 0431 - 君も始めようダイクストラ大好き厨
ユーザー名 ei2007
投稿日時 2020-12-14 17:50:20
言語 C++17
状態 Accepted
得点 1
ソースコード長 1090 Byte
最大実行時間 105 ms
最大メモリ使用量 7004 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
m_in1.txt AC 105 ms 7004 KB
1
r_in1.txt AC 32 ms 1468 KB
1
r_in2.txt AC 33 ms 1632 KB
1
r_in3.txt AC 38 ms 1832 KB
1
r_in4.txt AC 29 ms 1896 KB
1
r_in5.txt AC 36 ms 2032 KB
1
r_in6.txt AC 34 ms 2236 KB
1
r_in7.txt AC 28 ms 1264 KB
1
r_in8.txt AC 24 ms 1376 KB
1
r_in9.txt AC 40 ms 2440 KB
1
r_in10.txt AC 25 ms 1188 KB
1
r_in11.txt AC 31 ms 1576 KB
1
r_in12.txt AC 30 ms 1428 KB
1
r_in13.txt AC 32 ms 1700 KB
1
r_in14.txt AC 36 ms 1692 KB
1
r_in15.txt AC 35 ms 1848 KB
1
r_in16.txt AC 25 ms 1940 KB
1
r_in17.txt AC 28 ms 1952 KB
1
r_in18.txt AC 25 ms 2016 KB
1
r_in19.txt AC 25 ms 860 KB
1
r_in20.txt AC 28 ms 1024 KB
1
r_in21.txt AC 23 ms 840 KB
1
r_in22.txt AC 25 ms 952 KB
1
r_in23.txt AC 24 ms 1084 KB
1
r_in24.txt AC 22 ms 1132 KB
1
r_in25.txt AC 24 ms 1100 KB
1
r_in26.txt AC 32 ms 1320 KB
1
r_in27.txt AC 34 ms 1288 KB
1
r_in28.txt AC 30 ms 1468 KB
1
r_in29.txt AC 35 ms 1568 KB
1
r_in30.txt AC 33 ms 1680 KB
1