-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
42 lines (40 loc) · 696 Bytes
/
test.cpp
File metadata and controls
42 lines (40 loc) · 696 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
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
struct A {
int v,w;
bool operator < (const A& o) const {
return w > o.w;
}
};
vector<A> adj[N];
int d[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt","w", stdout);
#endif
int n,m;
cin >> n >> m;
while(m--) {
int u,v,w;
cin >> u >> v >> w;
u[adj].push_back({v, w});
}
memset(d, 0x3f, sizeof(d));
d[0] = 0;
priority_queue<A> pq;
pq.push({0,0});
while(!pq.empty()) {
int u = pq.top().v, w = pq.top().w;
pq.pop();
for(auto& x : adj[u] ) {
if(d[x.v] > w + x.w) {
d[x.v] = w+x.w;
pq.push({x.v, d[x.v]});
}
}
}
cout << (d[n-1]);
return 0;
}