-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Shortest_Routes_I.cpp
More file actions
78 lines (71 loc) · 1.41 KB
/
A_Shortest_Routes_I.cpp
File metadata and controls
78 lines (71 loc) · 1.41 KB
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const ll inf = LLONG_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;
int vis[100005], dis[100005];
vii adj[100005];
void dijkstra()
{
priority_queue<pii, vii, greater<pii>> pq;
pq.push({0, 1});
while (!pq.empty())
{
int u = pq.top().second;
pq.pop();
if (vis[u])
continue;
vis[u] = 1;
for (auto [v, w] : adj[u])
{
if (dis[v] > dis[u] + w)
{
dis[v] = dis[u] + w;
pq.push({dis[v], v});
}
}
}
}
void solve()
{
int n, m;
cin >> n >> m;
for (ll i = 0; i < m; i++)
{
int u, v, w;
cin >> u >> v >> w;
adj[u].pb({v, w});
}
for (int i = 2; i <= n; i++)
dis[i] = inf;
dijkstra();
for (int i = 1; i <= n; i++)
cout << dis[i] << " ";
}
signed main()
{
IOS;
int t = 1;
// cin>>t;
while (t--)
{
solve();
// cout<<'\n';
}
}