Submission #44488


ソースコード

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
78
79
80
81
82
83
84
85
#include "bits/stdc++.h" // {{{
using namespace std;
#define eb emplace_back
#define emp emplace
#define fi first
#define se second
#define X first
#define Y second
#define outl(x) cout << (x) << '\n'
#define rep(i,n) for(int i=0; i < (int)(n); ++i)
#define ALL(x) begin(x), end(x)
#define TMPLT(T,U) template<class T, class U>
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define show(x) clog << #x << " \t= " << (x) << '\n'
#define line() fputs("\n--------------------------------\n", stderr)
#else
#define debug(...)
#define show(x)
#define LN()
#endif
using ll = long long;
using pii = pair<int,int>;
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y) { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
inline bool inner(int val, int min, int max){ return min <= val && val < max; }
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f'3f3f3f3fLL;
namespace ydk{ // }}}
constexpr int LIM = (int)1e5 + 10;
int N, M;
vector<pii> G[LIM];
int mcos[LIM];
void dijkstra(int s)
{
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.emp(0, s);
memset(mcos, INF, sizeof(mcos));
mcos[s] = 0;
while(pq.size()) {
pii now = pq.top(); pq.pop();
if (now.fi > mcos[now.se]) continue;
for(pii e : G[now.se]) {
int nxt = e.se;
int newCost = e.fi + now.fi;
if (chmin(mcos[nxt], newCost)) {
pq.emp(newCost, nxt);
}
}
}
}
signed _vim_is_god_()
{
cin.tie(0), ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
G[a].eb(c, b);
G[b].eb(c, a);
}
dijkstra(1);
if (mcos[N] == INF) {
outl("NA");
} else {
outl(mcos[N]);
}
return 0;
}
} // {{{
signed main(){ydk::_vim_is_god_(); return 0;} // }}}

ステータス

項目 データ
問題 0431 - 君も始めようダイクストラ大好き厨
ユーザー名 Arumakan_ei1727
投稿日時 2018-10-31 21:54:21
言語 C++14
状態 Accepted
得点 1
ソースコード長 2245 Byte
最大実行時間 69 ms
最大メモリ使用量 7004 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
m_in1.txt AC 69 ms 7004 KB
1
r_in1.txt AC 25 ms 4000 KB
1
r_in2.txt AC 32 ms 4084 KB
1
r_in3.txt AC 29 ms 4320 KB
1
r_in4.txt AC 23 ms 3828 KB
1
r_in5.txt AC 29 ms 4480 KB
1
r_in6.txt AC 32 ms 4288 KB
1
r_in7.txt AC 26 ms 3764 KB
1
r_in8.txt AC 26 ms 3904 KB
1
r_in9.txt AC 35 ms 4632 KB
1
r_in10.txt AC 22 ms 3452 KB
1
r_in11.txt AC 30 ms 3956 KB
1
r_in12.txt AC 27 ms 3976 KB
1
r_in13.txt AC 30 ms 4096 KB
1
r_in14.txt AC 33 ms 4156 KB
1
r_in15.txt AC 33 ms 4296 KB
1
r_in16.txt AC 28 ms 3896 KB
1
r_in17.txt AC 27 ms 3900 KB
1
r_in18.txt AC 29 ms 3852 KB
1
r_in19.txt AC 28 ms 3504 KB
1
r_in20.txt AC 27 ms 3740 KB
1
r_in21.txt AC 23 ms 3516 KB
1
r_in22.txt AC 27 ms 3572 KB
1
r_in23.txt AC 23 ms 3668 KB
1
r_in24.txt AC 29 ms 3720 KB
1
r_in25.txt AC 31 ms 3848 KB
1
r_in26.txt AC 28 ms 3896 KB
1
r_in27.txt AC 37 ms 3976 KB
1
r_in28.txt AC 33 ms 4008 KB
1
r_in29.txt AC 30 ms 4132 KB
1
r_in30.txt AC 25 ms 4068 KB
1