forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1753.cpp
More file actions
57 lines (45 loc) · 927 Bytes
/
Copy path1753.cpp
File metadata and controls
57 lines (45 loc) · 927 Bytes
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
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
int V, E, K;
vector<pair<int, int>> Edges[20001];
int d[20001];
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> V >> E >> K;
int i, u, v, w;
for (i = 0; i < E; i++) {
cin >> u >> v >> w;
Edges[u].push_back({ w,v });
}
fill(d, d + V + 1, 1999999999);
d[K] = 0;
pq.push({ 0, K });
while (!pq.empty()) {
pair<int, int> now = pq.top();
pq.pop();
int v = now.second;
int w = now.first;
if (w > d[v])
continue;
for (pair<int, int> Edge : Edges[v]) {
int k = Edge.second;
if (d[k] > w + Edge.first) {
d[k] = w + Edge.first;
pq.push({ d[k], k });
}
}
}
for (i = 1; i <= V; i++) {
if (d[i] == 1999999999)
cout << "INF\n";
else cout << d[i] << "\n";
}
return 0;
}