Submission #64966


ソースコード

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
#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));
cost[1] = 0;
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 = edges[from][i].s;
if(nc + cost[from] < cost[to]){
cost[to] = nc + cost[from];
pq.push(mk(cost[to],to));
}
}
}
if(cost[n] == inf){
cout<<"NA\n";
}else{
cout<<cost[n]<<"\n";
}
return(0);
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
m_in1.txt AC 103 ms 7004 KB
1
r_in1.txt AC 37 ms 1464 KB
1
r_in2.txt AC 33 ms 1628 KB
1
r_in3.txt AC 35 ms 1720 KB
1
r_in4.txt AC 29 ms 1792 KB
1
r_in5.txt AC 43 ms 1928 KB
1
r_in6.txt AC 38 ms 2140 KB
1
r_in7.txt AC 27 ms 1304 KB
1
r_in8.txt AC 22 ms 1408 KB
1
r_in9.txt AC 42 ms 2600 KB
1
r_in10.txt AC 31 ms 1192 KB
1
r_in11.txt AC 36 ms 1440 KB
1
r_in12.txt AC 42 ms 1552 KB
1
r_in13.txt AC 33 ms 1604 KB
1
r_in14.txt AC 46 ms 1696 KB
1
r_in15.txt AC 39 ms 1852 KB
1
r_in16.txt AC 31 ms 1816 KB
1
r_in17.txt AC 26 ms 2084 KB
1
r_in18.txt AC 27 ms 2148 KB
1
r_in19.txt AC 26 ms 860 KB
1
r_in20.txt AC 34 ms 1024 KB
1
r_in21.txt AC 23 ms 708 KB
1
r_in22.txt AC 25 ms 824 KB
1
r_in23.txt AC 25 ms 828 KB
1
r_in24.txt AC 28 ms 1008 KB
1
r_in25.txt AC 38 ms 1236 KB
1
r_in26.txt AC 33 ms 1464 KB
1
r_in27.txt AC 25 ms 1304 KB
1
r_in28.txt AC 40 ms 1480 KB
1
r_in29.txt AC 31 ms 1576 KB
1
r_in30.txt AC 31 ms 1700 KB
1