Submission #65737


ソースコード

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>
#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed << setprecision(x)
using namespace std;
using pii = pair<int, int>;
template <class A, class B>
inline bool chmax(A& a, const B& b) {
return b > a && (a = b, true);
}
template <class A, class B>
inline bool chmin(A& a, const B& b) {
return b < a && (a = b, true);
}
template <class A>
inline A abs(A& a) {
return (a < 0 ? -a : a);
}
bool inLine(int x, int y, int mx, int my) {
return (x >= 0 && y >= 0 && x < mx && y < my);
}
const lol inf = (1LL << 62);
const int MOD = (1e9) + 7;
const int mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1, -2, -2, -2, -2,
-2, -1, -1, 1, 1, 0, 0, 2, 2, 2, 2, 2};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1, -2, -1, 0, 1,
2, -2, 2, -2, 2, -2, 2, -2, -1, 0, 1, 2};
struct ed{
int lo;
int cost;
ed(int a=0,int b=0){
lo=a;
cost=b;
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin >>n>>m;
vector<vector<ed>> lis(n);
for(int i=0;i<m;i++){
int a,b,c;
cin >>a>>b>>c;
a--;
b--;
lis[a].emplace_back(b,c);
lis[b].emplace_back(a,c);
}
priority_queue<tuple<int,int>,vector<tuple<int,int>>,greater<tuple<int,int>>> pq;
pq.emplace(0,0);
vector<int> ans(n,MOD);
ans[0]=0;
while(!pq.empty()){
auto [cost,p]=pq.top();
pq.pop();
for(auto[q,cs]:lis[p]){
if(chmin(ans[q],cost+cs)){
pq.emplace(cost+cs,q);
}
}
}
if(ans[n-1]!=MOD){
cout <<ans[n-1]<<'\n';
}else{
cout <<"NA\n";
}
return (0);
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
m_in1.txt AC 101 ms 8668 KB
1
r_in1.txt AC 54 ms 3484 KB
1
r_in2.txt AC 30 ms 6140 KB
1
r_in3.txt AC 26 ms 8256 KB
1
r_in4.txt AC 24 ms 8892 KB
1
r_in5.txt AC 32 ms 9516 KB
1
r_in6.txt AC 60 ms 9960 KB
1
r_in7.txt AC 50 ms 9220 KB
1
r_in8.txt AC 31 ms 9436 KB
1
r_in9.txt AC 49 ms 10988 KB
1
r_in10.txt AC 44 ms 3308 KB
1
r_in11.txt AC 31 ms 3920 KB
1
r_in12.txt AC 25 ms 4248 KB
1
r_in13.txt AC 51 ms 4660 KB
1
r_in14.txt AC 30 ms 4976 KB
1
r_in15.txt AC 29 ms 5344 KB
1
r_in16.txt AC 63 ms 5536 KB
1
r_in17.txt AC 42 ms 5776 KB
1
r_in18.txt AC 25 ms 6064 KB
1
r_in19.txt AC 26 ms 5264 KB
1
r_in20.txt AC 26 ms 5772 KB
1
r_in21.txt AC 44 ms 5552 KB
1
r_in22.txt AC 23 ms 5764 KB
1
r_in23.txt AC 21 ms 6004 KB
1
r_in24.txt AC 25 ms 6420 KB
1
r_in25.txt AC 24 ms 6616 KB
1
r_in26.txt AC 29 ms 6952 KB
1
r_in27.txt AC 22 ms 7284 KB
1
r_in28.txt AC 30 ms 7420 KB
1
r_in29.txt AC 32 ms 7752 KB
1
r_in30.txt AC 58 ms 8460 KB
1