-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps297.cpp
More file actions
62 lines (47 loc) · 1.09 KB
/
Copy pathneps297.cpp
File metadata and controls
62 lines (47 loc) · 1.09 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
/*
* Contest : Neps
* Problem : 297 - Caminho das Pontes
* Link : https://neps.academy/br/exercise/297
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
typedef pair<int, int> pii;
vector<vector<pii>> adj;
vector<int> dist;
vector<bool> visited;
int n, m, s, t, b;
void dijkstra(int ini) {
dist.assign(n + 2, INT_MAX);
priority_queue<pii> fila;
fila.push({0, ini});
dist[ini] = 0;
while (!fila.empty()) {
int atual = fila.top().second;
fila.pop();
if (visited[atual]) continue;
visited[atual] = true;
for (auto &V : adj[atual]) {
int peso = V.first, v = V.second;
if (dist[atual] + peso < dist[v]) {
dist[v] = dist[atual] + peso;
fila.push({-dist[v], v});
}
}
}
}
int main() {
fastio
scanf("%i %i", &n, &m);
adj.assign(n + 2, vector<pii>());
visited.assign(n + 2, false);
while (m--) {
scanf("%i %i %i", &s, &t, &b);
adj[s].push_back({b, t});
adj[t].push_back({b, s});
}
dijkstra(0);
printf("%i\n", dist[n + 1]);
return 0;
}