Submission #58892


ソースコード

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
86
87
88
89
90
91
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
vector<int> Div(int n) {
vector<int> ret;
for(int i = 1; i * i <= n; ++i) {
if(n % i == 0) {
ret.pb(i);
if(i * i != n) ret.pb(n / i);
}
}
sort(all(ret));
return ret;
}
LL dijkstra(int s, int t);
vector<LP> graph[SIZE];
LL dist[SIZE];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int v, e;
cin >> v >> e;
while(e--) {
LL a, b, c;
cin >> a >> b >> c;
graph[a].pb(MP(b, c));
graph[b].pb(MP(a, c));
}
cout << dijkstra(1, v) << endl;
return 0;
}
LL dijkstra(int s, int t) {
priority_queue<LP, vector<LP>, greater<LP>> pq;
pq.push(MP(0, s));
for(int i = 1; i < SIZE; ++i) {
dist[i] = LINF;
}
dist[1] = 0;
while(!pq.empty()) {
LP node = pq.top();
pq.pop();
if(node.F > dist[node.S]) continue;
for(int i = 0; i < graph[node.S].size(); ++i) {
LP p = graph[node.S][i];
if(dist[node.S] + p.S < dist[p.F]) {
dist[p.F] = dist[node.S] + p.S;
pq.push(MP(dist[p.F], p.F));
}
}
}
return dist[t];
}

ステータス

項目 データ
問題 1257 - ダイクストラ大好き厨とコーナーテストケース
ユーザー名 crom
投稿日時 2020-03-26 22:27:43
言語 C++14
状態 Accepted
得点 5
ソースコード長 1867 Byte
最大実行時間 104 ms
最大メモリ使用量 18380 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
corner_input.txt AC 74 ms 18380 KB
1
input01.txt AC 104 ms 17796 KB
1
input02.txt AC 73 ms 14396 KB
1
input03.txt AC 71 ms 13728 KB
1
input04.txt AC 74 ms 16344 KB
1
input05.txt AC 64 ms 17036 KB
1
sample_input.txt AC 20 ms 6868 KB
1