Submission #58138


ソースコード

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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;
//===
template<class T>
struct Edge {
int src, to;
T cost;
Edge (int to, T cost):
src(-1), to(to), cost(cost) {};
Edge (int src, int to, T cost):
src(src), to(to), cost(cost) {};
operator int() const {
return to;
};
};
template <class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using UnWeightedGraph = vector<vector<int> >;
//===
//===
// require graph/basic.cpp
// #include <limits>
// #include <queue>
// if s->u path is nothing, min_cost[u] = numeric_limits<T>::max()
// time:O((V+E) log V)
template<class T>
vector<T> dijkstra(WeightedGraph<T> &g, int s) {
const T INF = numeric_limits<T>::max();
using P = pair<T, int>;
vector<T> min_cost(g.size(), INF);
//vector<T> restore(g.size(), -1);
priority_queue<P, vector<P>, greater<P> > que;
que.emplace(0, s);
while (!que.empty()) {
T cost = que.top().first;
int pos = que.top().second;
que.pop();
if (min_cost[pos] != INF) continue;
min_cost[pos] = cost;
for (Edge<T> e:g[pos]) {
if (min_cost[e.to] <= cost + e.cost) continue;
que.emplace(cost + e.cost, e.to);
//restore[npos] = pos;
}
}
return min_cost;
};
//===
int main() {
llong v, e;
llong s, t, d;
const llong INF = numeric_limits<llong>::max();
cin >> v >> e;
WeightedGraph<llong> g(v + 1);
for (int i = 0; i < e; i++) {
cin >> s >> t >> d;
g[s].emplace_back(t, d);
g[t].emplace_back(s, d);
}
vector<llong> dist = dijkstra(g, 1);
cout << dist[v] << endl;
return 0;
}

ステータス

項目 データ
問題 1257 - ダイクストラ大好き厨とコーナーテストケース
ユーザー名 ei1710
投稿日時 2020-01-15 15:31:41
言語 C++14
状態 Accepted
得点 5
ソースコード長 2011 Byte
最大実行時間 192 ms
最大メモリ使用量 16328 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
corner_input.txt AC 154 ms 15308 KB
1
input01.txt AC 192 ms 15692 KB
1
input02.txt AC 119 ms 10232 KB
1
input03.txt AC 116 ms 9956 KB
1
input04.txt AC 144 ms 12272 KB
1
input05.txt AC 139 ms 16328 KB
1
sample_input.txt AC 25 ms 544 KB
1